Skip to content

Commit 045ee36

Browse files
committed
chore: migrate to direct invocations
1 parent bcb3f5b commit 045ee36

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,
@@ -639,44 +635,44 @@ const encodingOps = {
639635
encoding: 'utf8',
640636
encodingVal: encodingsMap.utf8,
641637
byteLength: byteLengthUtf8,
642-
write: (buf, string, offset, len) => FunctionPrototypeCall(utf8Write, buf, string, offset, len),
643-
slice: (buf, start, end) => FunctionPrototypeCall(utf8Slice, buf, start, end),
638+
write: utf8Write,
639+
slice: utf8Slice,
644640
indexOf: (buf, val, byteOffset, dir) =>
645641
indexOfString(buf, val, byteOffset, encodingsMap.utf8, dir),
646642
},
647643
ucs2: {
648644
encoding: 'ucs2',
649645
encodingVal: encodingsMap.utf16le,
650646
byteLength: (string) => string.length * 2,
651-
write: (buf, string, offset, len) => FunctionPrototypeCall(ucs2Write, buf, string, offset, len),
652-
slice: (buf, start, end) => FunctionPrototypeCall(ucs2Slice, buf, start, end),
647+
write: ucs2Write,
648+
slice: ucs2Slice,
653649
indexOf: (buf, val, byteOffset, dir) =>
654650
indexOfString(buf, val, byteOffset, encodingsMap.utf16le, dir),
655651
},
656652
utf16le: {
657653
encoding: 'utf16le',
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
latin1: {
666662
encoding: 'latin1',
667663
encodingVal: encodingsMap.latin1,
668664
byteLength: (string) => string.length,
669-
write: (buf, string, offset, len) => FunctionPrototypeCall(latin1Write, buf, string, offset, len),
670-
slice: (buf, start, end) => FunctionPrototypeCall(latin1Slice, buf, start, end),
665+
write: latin1Write,
666+
slice: latin1Slice,
671667
indexOf: (buf, val, byteOffset, dir) =>
672668
indexOfString(buf, val, byteOffset, encodingsMap.latin1, dir),
673669
},
674670
ascii: {
675671
encoding: 'ascii',
676672
encodingVal: encodingsMap.ascii,
677673
byteLength: (string) => string.length,
678-
write: (buf, string, offset, len) => FunctionPrototypeCall(asciiWrite, buf, string, offset, len),
679-
slice: (buf, start, end) => FunctionPrototypeCall(asciiSlice, buf, start, end),
674+
write: asciiWrite,
675+
slice: asciiSlice,
680676
indexOf: (buf, val, byteOffset, dir) =>
681677
indexOfBuffer(buf,
682678
fromStringFast(val, encodingOps.ascii),
@@ -688,8 +684,8 @@ const encodingOps = {
688684
encoding: 'base64',
689685
encodingVal: encodingsMap.base64,
690686
byteLength: (string) => base64ByteLength(string, string.length),
691-
write: (buf, string, offset, len) => FunctionPrototypeCall(base64Write, buf, string, offset, len),
692-
slice: (buf, start, end) => FunctionPrototypeCall(base64Slice, buf, start, end),
687+
write: base64Write,
688+
slice: base64Slice,
693689
indexOf: (buf, val, byteOffset, dir) =>
694690
indexOfBuffer(buf,
695691
fromStringFast(val, encodingOps.base64),
@@ -701,9 +697,8 @@ const encodingOps = {
701697
encoding: 'base64url',
702698
encodingVal: encodingsMap.base64url,
703699
byteLength: (string) => base64ByteLength(string, string.length),
704-
write: (buf, string, offset, len) =>
705-
FunctionPrototypeCall(base64urlWrite, buf, string, offset, len),
706-
slice: (buf, start, end) => FunctionPrototypeCall(base64urlSlice, buf, start, end),
700+
write: base64urlWrite,
701+
slice: base64urlSlice,
707702
indexOf: (buf, val, byteOffset, dir) =>
708703
indexOfBuffer(buf,
709704
fromStringFast(val, encodingOps.base64url),
@@ -715,8 +710,8 @@ const encodingOps = {
715710
encoding: 'hex',
716711
encodingVal: encodingsMap.hex,
717712
byteLength: (string) => string.length >>> 1,
718-
write: (buf, string, offset, len) => FunctionPrototypeCall(hexWrite, buf, string, offset, len),
719-
slice: (buf, start, end) => FunctionPrototypeCall(hexSlice, buf, start, end),
713+
write: hexWrite,
714+
slice: hexSlice,
720715
indexOf: (buf, val, byteOffset, dir) =>
721716
indexOfBuffer(buf,
722717
fromStringFast(val, encodingOps.hex),
@@ -841,7 +836,7 @@ Buffer.prototype.copy =
841836
// to their upper/lower bounds if the value passed is out of range.
842837
Buffer.prototype.toString = function toString(encoding, start, end) {
843838
if (arguments.length === 0) {
844-
return FunctionPrototypeCall(utf8Slice, this, 0, this.length);
839+
return utf8Slice(this, 0, this.length);
845840
}
846841

847842
const len = this.length;
@@ -862,7 +857,7 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
862857
return '';
863858

864859
if (encoding === undefined)
865-
return FunctionPrototypeCall(utf8Slice, this, start, end);
860+
return utf8Slice(this, start, end);
866861

867862
const ops = getEncodingOps(encoding);
868863
if (ops === undefined)
@@ -893,7 +888,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
893888
const actualMax = MathMin(max, this.length);
894889
const remaining = this.length - max;
895890
let str = StringPrototypeTrim(RegExpPrototypeSymbolReplace(
896-
/(.{2})/g, FunctionPrototypeCall(hexSlice, this, 0, actualMax), '$1 '));
891+
/(.{2})/g, hexSlice(this, 0, actualMax), '$1 '));
897892
if (remaining > 0)
898893
str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`;
899894
// Inspect special properties as well, if possible.
@@ -1117,7 +1112,7 @@ function _fill(buf, value, offset, end, encoding) {
11171112
Buffer.prototype.write = function write(string, offset, length, encoding) {
11181113
// Buffer#write(string);
11191114
if (offset === undefined) {
1120-
return FunctionPrototypeCall(utf8Write, this, string, 0, this.length);
1115+
return utf8Write(this, string, 0, this.length);
11211116
}
11221117
// Buffer#write(string, encoding)
11231118
if (length === undefined && typeof offset === 'string') {
@@ -1144,9 +1139,9 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
11441139
}
11451140

11461141
if (!encoding || encoding === 'utf8')
1147-
return FunctionPrototypeCall(utf8Write, this, string, offset, length);
1142+
return utf8Write(this, string, offset, length);
11481143
if (encoding === 'ascii')
1149-
return FunctionPrototypeCall(asciiWrite, this, string, offset, length);
1144+
return asciiWrite(this, string, offset, length);
11501145

11511146
const ops = getEncodingOps(encoding);
11521147
if (ops === undefined)

0 commit comments

Comments
 (0)