Skip to content

Commit 7c8b68d

Browse files
committed
improve variable names and add Refs
1 parent 49e79cc commit 7c8b68d

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

lib/buffer.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,30 +1171,30 @@ function _fill(buf, value, offset, end, encoding) {
11711171
}
11721172

11731173
Buffer.prototype.write = function write(string, offset, length, encoding) {
1174-
const len = this.length;
1174+
const bufferLength = this.length;
11751175
// Buffer#write(string);
11761176
if (offset === undefined) {
1177-
return utf8Write(this, string, 0, len);
1177+
return utf8Write(this, string, 0, bufferLength);
11781178
}
11791179
// Buffer#write(string, encoding)
11801180
if (length === undefined && typeof offset === 'string') {
11811181
encoding = offset;
1182-
length = len;
1182+
length = bufferLength;
11831183
offset = 0;
11841184

11851185
// Buffer#write(string, offset[, length][, encoding])
11861186
} else {
1187-
validateOffset(offset, 'offset', 0, len);
1187+
validateOffset(offset, 'offset', 0, bufferLength);
11881188

1189-
const remaining = len - offset;
1189+
const remaining = bufferLength - offset;
11901190

11911191
if (length === undefined) {
11921192
length = remaining;
11931193
} else if (typeof length === 'string') {
11941194
encoding = length;
11951195
length = remaining;
11961196
} else {
1197-
validateOffset(length, 'length', 0, len);
1197+
validateOffset(length, 'length', 0, bufferLength);
11981198
if (length > remaining)
11991199
length = remaining;
12001200
}
@@ -1258,6 +1258,7 @@ function swap(b, n, m) {
12581258
}
12591259

12601260
Buffer.prototype.swap16 = function swap16() {
1261+
// Ref: https://github.com/nodejs/node/pull/61871#discussion_r2889557696
12611262
// For Buffer.length <= 32, it's generally faster to
12621263
// do the swap in javascript. For larger buffers,
12631264
// dropping down to the native code is faster.
@@ -1274,6 +1275,7 @@ Buffer.prototype.swap16 = function swap16() {
12741275
};
12751276

12761277
Buffer.prototype.swap32 = function swap32() {
1278+
// Ref: https://github.com/nodejs/node/pull/61871#discussion_r2889557696
12771279
// For Buffer.length <= 32, it's generally faster to
12781280
// do the swap in javascript. For larger buffers,
12791281
// dropping down to the native code is faster.
@@ -1292,9 +1294,12 @@ Buffer.prototype.swap32 = function swap32() {
12921294
};
12931295

12941296
Buffer.prototype.swap64 = function swap64() {
1297+
// Ref: https://github.com/nodejs/node/pull/61871#discussion_r2889557696
12951298
// For Buffer.length < 48, it's generally faster to
12961299
// do the swap in javascript. For larger buffers,
12971300
// dropping down to the native code is faster.
1301+
// Threshold differs from swap16/swap32 (<=32) because swap64's
1302+
// crossover is between 40 and 48 (native wins at 48, loses at 40).
12981303
const len = TypedArrayPrototypeGetLength(this);
12991304
if (len % 8 !== 0)
13001305
throw new ERR_INVALID_BUFFER_SIZE('64-bits');

0 commit comments

Comments
 (0)