rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
28 lines • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayCopyInto = void 0;
const _debug_js_1 = require("../../debug/_debug.js");
/**
* @public
* Make an array contain the same items as another.
* @param from - The array to copy from.
* @param to - The array to copy into and resize.
* @param startIndex - The index to start with in the from array.
* @param length - The index to end with in the from array.
*
* @remarks
* See {@link arrayCopyInto}.
*/
function arrayCopyInto(from, to, startIndex = 0, length = from.length) {
const end = startIndex + length;
to.length = length;
_BUILD.DEBUG && _debug_js_1._Debug.runBlock(() => {
_debug_js_1._Debug.assert(startIndex >= 0, "negative indexes are not supported");
_debug_js_1._Debug.assert(end <= from.length, "length would overflow array");
});
for (let i = 0; startIndex < end; ++startIndex, ++i) {
to[i] = from[startIndex];
}
}
exports.arrayCopyInto = arrayCopyInto;
//# sourceMappingURL=array-copy-into.js.map