buffer: alias subarray and slice

PR-URL: https://github.com/nodejs/node/pull/41596
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Benjamin Gruenbaum 2022-01-19 20:31:49 +02:00 committed by Antoine du Hamel
parent 6bf769e4e6
commit 3d23d62373

View file

@ -1112,7 +1112,7 @@ function adjustOffset(offset, length) {
return NumberIsNaN(offset) ? 0 : length;
}
Buffer.prototype.slice = function slice(start, end) {
Buffer.prototype.subarray = function subarray(start, end) {
const srcLength = this.length;
start = adjustOffset(start, srcLength);
end = end !== undefined ? adjustOffset(end, srcLength) : srcLength;
@ -1120,6 +1120,10 @@ Buffer.prototype.slice = function slice(start, end) {
return new FastBuffer(this.buffer, this.byteOffset + start, newLength);
};
Buffer.prototype.slice = function slice(start, end) {
return this.subarray(start, end);
};
function swap(b, n, m) {
const i = b[n];
b[n] = b[m];