Skip to content

Commit 4073cae

Browse files
committed
wip
1 parent 581976d commit 4073cae

File tree

5 files changed

+173
-169
lines changed

5 files changed

+173
-169
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,
@@ -74,6 +73,17 @@ const {
7473
kStringMaxLength,
7574
atob: _atob,
7675
btoa: _btoa,
76+
asciiSlice,
77+
base64Slice,
78+
base64urlSlice,
79+
latin1Slice,
80+
hexSlice,
81+
ucs2Slice,
82+
utf8Slice,
83+
base64Write,
84+
base64urlWrite,
85+
hexWrite,
86+
ucs2Write,
7787
} = internalBinding('buffer');
7888
const {
7989
constants: {
@@ -130,29 +140,15 @@ const {
130140
markAsUntransferable,
131141
addBufferPrototypeMethods,
132142
createUnsafeBuffer,
143+
asciiWrite,
144+
latin1Write,
145+
utf8Write,
133146
} = require('internal/buffer');
134147

135148
FastBuffer.prototype.constructor = Buffer;
136149
Buffer.prototype = FastBuffer.prototype;
137150
addBufferPrototypeMethods(Buffer.prototype);
138151

139-
const {
140-
asciiWrite,
141-
latin1Write,
142-
utf8Write,
143-
asciiSlice,
144-
base64Slice,
145-
base64urlSlice,
146-
latin1Slice,
147-
hexSlice,
148-
ucs2Slice,
149-
utf8Slice,
150-
base64Write,
151-
base64urlWrite,
152-
hexWrite,
153-
ucs2Write,
154-
} = Buffer.prototype;
155-
156152
const constants = ObjectDefineProperties({}, {
157153
MAX_LENGTH: {
158154
__proto__: null,
@@ -651,44 +647,44 @@ const encodingOps = {
651647
encoding: 'utf8',
652648
encodingVal: encodingsMap.utf8,
653649
byteLength: byteLengthUtf8,
654-
write: (buf, string, offset, len) => FunctionPrototypeCall(utf8Write, buf, string, offset, len),
655-
slice: (buf, start, end) => FunctionPrototypeCall(utf8Slice, buf, start, end),
650+
write: utf8Write,
651+
slice: utf8Slice,
656652
indexOf: (buf, val, byteOffset, dir) =>
657653
indexOfString(buf, val, byteOffset, encodingsMap.utf8, dir),
658654
},
659655
ucs2: {
660656
encoding: 'ucs2',
661657
encodingVal: encodingsMap.utf16le,
662658
byteLength: (string) => string.length * 2,
663-
write: (buf, string, offset, len) => FunctionPrototypeCall(ucs2Write, buf, string, offset, len),
664-
slice: (buf, start, end) => FunctionPrototypeCall(ucs2Slice, buf, start, end),
659+
write: ucs2Write,
660+
slice: ucs2Slice,
665661
indexOf: (buf, val, byteOffset, dir) =>
666662
indexOfString(buf, val, byteOffset, encodingsMap.utf16le, dir),
667663
},
668664
utf16le: {
669665
encoding: 'utf16le',
670666
encodingVal: encodingsMap.utf16le,
671667
byteLength: (string) => string.length * 2,
672-
write: (buf, string, offset, len) => FunctionPrototypeCall(ucs2Write, buf, string, offset, len),
673-
slice: (buf, start, end) => FunctionPrototypeCall(ucs2Slice, buf, start, end),
668+
write: ucs2Write,
669+
slice: ucs2Slice,
674670
indexOf: (buf, val, byteOffset, dir) =>
675671
indexOfString(buf, val, byteOffset, encodingsMap.utf16le, dir),
676672
},
677673
latin1: {
678674
encoding: 'latin1',
679675
encodingVal: encodingsMap.latin1,
680676
byteLength: (string) => string.length,
681-
write: (buf, string, offset, len) => FunctionPrototypeCall(latin1Write, buf, string, offset, len),
682-
slice: (buf, start, end) => FunctionPrototypeCall(latin1Slice, buf, start, end),
677+
write: latin1Write,
678+
slice: latin1Slice,
683679
indexOf: (buf, val, byteOffset, dir) =>
684680
indexOfString(buf, val, byteOffset, encodingsMap.latin1, dir),
685681
},
686682
ascii: {
687683
encoding: 'ascii',
688684
encodingVal: encodingsMap.ascii,
689685
byteLength: (string) => string.length,
690-
write: (buf, string, offset, len) => FunctionPrototypeCall(asciiWrite, buf, string, offset, len),
691-
slice: (buf, start, end) => FunctionPrototypeCall(asciiSlice, buf, start, end),
686+
write: asciiWrite,
687+
slice: asciiSlice,
692688
indexOf: (buf, val, byteOffset, dir) =>
693689
indexOfBuffer(buf,
694690
fromStringFast(val, encodingOps.ascii),
@@ -700,8 +696,8 @@ const encodingOps = {
700696
encoding: 'base64',
701697
encodingVal: encodingsMap.base64,
702698
byteLength: (string) => base64ByteLength(string, string.length),
703-
write: (buf, string, offset, len) => FunctionPrototypeCall(base64Write, buf, string, offset, len),
704-
slice: (buf, start, end) => FunctionPrototypeCall(base64Slice, buf, start, end),
699+
write: base64Write,
700+
slice: base64Slice,
705701
indexOf: (buf, val, byteOffset, dir) =>
706702
indexOfBuffer(buf,
707703
fromStringFast(val, encodingOps.base64),
@@ -713,9 +709,8 @@ const encodingOps = {
713709
encoding: 'base64url',
714710
encodingVal: encodingsMap.base64url,
715711
byteLength: (string) => base64ByteLength(string, string.length),
716-
write: (buf, string, offset, len) =>
717-
FunctionPrototypeCall(base64urlWrite, buf, string, offset, len),
718-
slice: (buf, start, end) => FunctionPrototypeCall(base64urlSlice, buf, start, end),
712+
write: base64urlWrite,
713+
slice: base64urlSlice,
719714
indexOf: (buf, val, byteOffset, dir) =>
720715
indexOfBuffer(buf,
721716
fromStringFast(val, encodingOps.base64url),
@@ -727,8 +722,8 @@ const encodingOps = {
727722
encoding: 'hex',
728723
encodingVal: encodingsMap.hex,
729724
byteLength: (string) => string.length >>> 1,
730-
write: (buf, string, offset, len) => FunctionPrototypeCall(hexWrite, buf, string, offset, len),
731-
slice: (buf, start, end) => FunctionPrototypeCall(hexSlice, buf, start, end),
725+
write: hexWrite,
726+
slice: hexSlice,
732727
indexOf: (buf, val, byteOffset, dir) =>
733728
indexOfBuffer(buf,
734729
fromStringFast(val, encodingOps.hex),
@@ -853,7 +848,7 @@ Buffer.prototype.copy =
853848
// to their upper/lower bounds if the value passed is out of range.
854849
Buffer.prototype.toString = function toString(encoding, start, end) {
855850
if (arguments.length === 0) {
856-
return FunctionPrototypeCall(utf8Slice, this, 0, this.length);
851+
return utf8Slice(this, 0, this.length);
857852
}
858853

859854
const len = this.length;
@@ -874,7 +869,7 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
874869
return '';
875870

876871
if (encoding === undefined)
877-
return FunctionPrototypeCall(utf8Slice, this, start, end);
872+
return utf8Slice(this, start, end);
878873

879874
const ops = getEncodingOps(encoding);
880875
if (ops === undefined)
@@ -905,7 +900,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
905900
const actualMax = MathMin(max, this.length);
906901
const remaining = this.length - max;
907902
let str = StringPrototypeTrim(RegExpPrototypeSymbolReplace(
908-
/(.{2})/g, FunctionPrototypeCall(hexSlice, this, 0, actualMax), '$1 '));
903+
/(.{2})/g, hexSlice(this, 0, actualMax), '$1 '));
909904
if (remaining > 0)
910905
str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`;
911906
// Inspect special properties as well, if possible.
@@ -1129,7 +1124,7 @@ function _fill(buf, value, offset, end, encoding) {
11291124
Buffer.prototype.write = function write(string, offset, length, encoding) {
11301125
// Buffer#write(string);
11311126
if (offset === undefined) {
1132-
return FunctionPrototypeCall(utf8Write, this, string, 0, this.length);
1127+
return utf8Write(this, string, 0, this.length);
11331128
}
11341129
// Buffer#write(string, encoding)
11351130
if (length === undefined && typeof offset === 'string') {
@@ -1156,9 +1151,9 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
11561151
}
11571152

11581153
if (!encoding || encoding === 'utf8')
1159-
return FunctionPrototypeCall(utf8Write, this, string, offset, length);
1154+
return utf8Write(this, string, offset, length);
11601155
if (encoding === 'ascii')
1161-
return FunctionPrototypeCall(asciiWrite, this, string, offset, length);
1156+
return asciiWrite(this, string, offset, length);
11621157

11631158
const ops = getEncodingOps(encoding);
11641159
if (ops === undefined)

0 commit comments

Comments
 (0)