Skip to content

Commit 7059501

Browse files
committed
chore: migrate to direct invocations
1 parent b425720 commit 7059501

File tree

5 files changed

+174
-170
lines changed

5 files changed

+174
-170
lines changed

lib/buffer.js

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const {
2626
ArrayBufferIsView,
2727
ArrayIsArray,
2828
ArrayPrototypeForEach,
29-
FunctionPrototypeCall,
3029
MathFloor,
3130
MathMin,
3231
MathTrunc,
@@ -73,6 +72,17 @@ const {
7372
kStringMaxLength,
7473
atob: _atob,
7574
btoa: _btoa,
75+
asciiSlice,
76+
base64Slice,
77+
base64urlSlice,
78+
latin1Slice,
79+
hexSlice,
80+
ucs2Slice,
81+
utf8Slice,
82+
base64Write,
83+
base64urlWrite,
84+
hexWrite,
85+
ucs2Write,
7686
} = internalBinding('buffer');
7787
const {
7888
constants: {
@@ -128,29 +138,15 @@ const {
128138
markAsUntransferable,
129139
addBufferPrototypeMethods,
130140
createUnsafeBuffer,
141+
asciiWrite,
142+
latin1Write,
143+
utf8Write,
131144
} = require('internal/buffer');
132145

133146
FastBuffer.prototype.constructor = Buffer;
134147
Buffer.prototype = FastBuffer.prototype;
135148
addBufferPrototypeMethods(Buffer.prototype);
136149

137-
const {
138-
asciiWrite,
139-
latin1Write,
140-
utf8Write,
141-
asciiSlice,
142-
base64Slice,
143-
base64urlSlice,
144-
latin1Slice,
145-
hexSlice,
146-
ucs2Slice,
147-
utf8Slice,
148-
base64Write,
149-
base64urlWrite,
150-
hexWrite,
151-
ucs2Write,
152-
} = Buffer.prototype;
153-
154150
const constants = ObjectDefineProperties({}, {
155151
MAX_LENGTH: {
156152
__proto__: null,
@@ -648,44 +644,44 @@ const encodingOps = {
648644
encoding: 'utf8',
649645
encodingVal: encodingsMap.utf8,
650646
byteLength: byteLengthUtf8,
651-
write: (buf, string, offset, len) => FunctionPrototypeCall(utf8Write, buf, string, offset, len),
652-
slice: (buf, start, end) => FunctionPrototypeCall(utf8Slice, buf, start, end),
647+
write: utf8Write,
648+
slice: utf8Slice,
653649
indexOf: (buf, val, byteOffset, dir) =>
654650
indexOfString(buf, val, byteOffset, encodingsMap.utf8, dir),
655651
},
656652
ucs2: {
657653
encoding: 'ucs2',
658654
encodingVal: encodingsMap.utf16le,
659655
byteLength: (string) => string.length * 2,
660-
write: (buf, string, offset, len) => FunctionPrototypeCall(ucs2Write, buf, string, offset, len),
661-
slice: (buf, start, end) => FunctionPrototypeCall(ucs2Slice, buf, start, end),
656+
write: ucs2Write,
657+
slice: ucs2Slice,
662658
indexOf: (buf, val, byteOffset, dir) =>
663659
indexOfString(buf, val, byteOffset, encodingsMap.utf16le, dir),
664660
},
665661
utf16le: {
666662
encoding: 'utf16le',
667663
encodingVal: encodingsMap.utf16le,
668664
byteLength: (string) => string.length * 2,
669-
write: (buf, string, offset, len) => FunctionPrototypeCall(ucs2Write, buf, string, offset, len),
670-
slice: (buf, start, end) => FunctionPrototypeCall(ucs2Slice, buf, start, end),
665+
write: ucs2Write,
666+
slice: ucs2Slice,
671667
indexOf: (buf, val, byteOffset, dir) =>
672668
indexOfString(buf, val, byteOffset, encodingsMap.utf16le, dir),
673669
},
674670
latin1: {
675671
encoding: 'latin1',
676672
encodingVal: encodingsMap.latin1,
677673
byteLength: (string) => string.length,
678-
write: (buf, string, offset, len) => FunctionPrototypeCall(latin1Write, buf, string, offset, len),
679-
slice: (buf, start, end) => FunctionPrototypeCall(latin1Slice, buf, start, end),
674+
write: latin1Write,
675+
slice: latin1Slice,
680676
indexOf: (buf, val, byteOffset, dir) =>
681677
indexOfString(buf, val, byteOffset, encodingsMap.latin1, dir),
682678
},
683679
ascii: {
684680
encoding: 'ascii',
685681
encodingVal: encodingsMap.ascii,
686682
byteLength: (string) => string.length,
687-
write: (buf, string, offset, len) => FunctionPrototypeCall(asciiWrite, buf, string, offset, len),
688-
slice: (buf, start, end) => FunctionPrototypeCall(asciiSlice, buf, start, end),
683+
write: asciiWrite,
684+
slice: asciiSlice,
689685
indexOf: (buf, val, byteOffset, dir) =>
690686
indexOfBuffer(buf,
691687
fromStringFast(val, encodingOps.ascii),
@@ -697,8 +693,8 @@ const encodingOps = {
697693
encoding: 'base64',
698694
encodingVal: encodingsMap.base64,
699695
byteLength: (string) => base64ByteLength(string, string.length),
700-
write: (buf, string, offset, len) => FunctionPrototypeCall(base64Write, buf, string, offset, len),
701-
slice: (buf, start, end) => FunctionPrototypeCall(base64Slice, buf, start, end),
696+
write: base64Write,
697+
slice: base64Slice,
702698
indexOf: (buf, val, byteOffset, dir) =>
703699
indexOfBuffer(buf,
704700
fromStringFast(val, encodingOps.base64),
@@ -710,9 +706,8 @@ const encodingOps = {
710706
encoding: 'base64url',
711707
encodingVal: encodingsMap.base64url,
712708
byteLength: (string) => base64ByteLength(string, string.length),
713-
write: (buf, string, offset, len) =>
714-
FunctionPrototypeCall(base64urlWrite, buf, string, offset, len),
715-
slice: (buf, start, end) => FunctionPrototypeCall(base64urlSlice, buf, start, end),
709+
write: base64urlWrite,
710+
slice: base64urlSlice,
716711
indexOf: (buf, val, byteOffset, dir) =>
717712
indexOfBuffer(buf,
718713
fromStringFast(val, encodingOps.base64url),
@@ -724,8 +719,8 @@ const encodingOps = {
724719
encoding: 'hex',
725720
encodingVal: encodingsMap.hex,
726721
byteLength: (string) => string.length >>> 1,
727-
write: (buf, string, offset, len) => FunctionPrototypeCall(hexWrite, buf, string, offset, len),
728-
slice: (buf, start, end) => FunctionPrototypeCall(hexSlice, buf, start, end),
722+
write: hexWrite,
723+
slice: hexSlice,
729724
indexOf: (buf, val, byteOffset, dir) =>
730725
indexOfBuffer(buf,
731726
fromStringFast(val, encodingOps.hex),
@@ -850,7 +845,7 @@ Buffer.prototype.copy =
850845
// to their upper/lower bounds if the value passed is out of range.
851846
Buffer.prototype.toString = function toString(encoding, start, end) {
852847
if (arguments.length === 0) {
853-
return FunctionPrototypeCall(utf8Slice, this, 0, this.length);
848+
return utf8Slice(this, 0, this.length);
854849
}
855850

856851
const len = this.length;
@@ -871,7 +866,7 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
871866
return '';
872867

873868
if (encoding === undefined)
874-
return FunctionPrototypeCall(utf8Slice, this, start, end);
869+
return utf8Slice(this, start, end);
875870

876871
const ops = getEncodingOps(encoding);
877872
if (ops === undefined)
@@ -902,7 +897,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
902897
const actualMax = MathMin(max, this.length);
903898
const remaining = this.length - max;
904899
let str = StringPrototypeTrim(RegExpPrototypeSymbolReplace(
905-
/(.{2})/g, FunctionPrototypeCall(hexSlice, this, 0, actualMax), '$1 '));
900+
/(.{2})/g, hexSlice(this, 0, actualMax), '$1 '));
906901
if (remaining > 0)
907902
str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`;
908903
// Inspect special properties as well, if possible.
@@ -1126,7 +1121,7 @@ function _fill(buf, value, offset, end, encoding) {
11261121
Buffer.prototype.write = function write(string, offset, length, encoding) {
11271122
// Buffer#write(string);
11281123
if (offset === undefined) {
1129-
return FunctionPrototypeCall(utf8Write, this, string, 0, this.length);
1124+
return utf8Write(this, string, 0, this.length);
11301125
}
11311126
// Buffer#write(string, encoding)
11321127
if (length === undefined && typeof offset === 'string') {
@@ -1153,9 +1148,9 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
11531148
}
11541149

11551150
if (!encoding || encoding === 'utf8')
1156-
return FunctionPrototypeCall(utf8Write, this, string, offset, length);
1151+
return utf8Write(this, string, offset, length);
11571152
if (encoding === 'ascii')
1158-
return FunctionPrototypeCall(asciiWrite, this, string, offset, length);
1153+
return asciiWrite(this, string, offset, length);
11591154

11601155
const ops = getEncodingOps(encoding);
11611156
if (ops === undefined)

0 commit comments

Comments
 (0)