Skip to content

Commit

Permalink
buffer: alias subarray and slice
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
benjamingr authored and danielleadams committed Apr 21, 2022
1 parent 3d4df9c commit 84752a4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/buffer.js
Expand Up @@ -1113,14 +1113,18 @@ 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;
const newLength = end > start ? end - start : 0;
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];
Expand Down

0 comments on commit 84752a4

Please sign in to comment.