@@ -26,7 +26,6 @@ const {
26
26
ArrayBufferIsView,
27
27
ArrayIsArray,
28
28
ArrayPrototypeForEach,
29
- FunctionPrototypeCall,
30
29
MathFloor,
31
30
MathMin,
32
31
MathTrunc,
@@ -74,6 +73,17 @@ const {
74
73
kStringMaxLength,
75
74
atob : _atob ,
76
75
btoa : _btoa ,
76
+ asciiSlice,
77
+ base64Slice,
78
+ base64urlSlice,
79
+ latin1Slice,
80
+ hexSlice,
81
+ ucs2Slice,
82
+ utf8Slice,
83
+ base64Write,
84
+ base64urlWrite,
85
+ hexWrite,
86
+ ucs2Write,
77
87
} = internalBinding ( 'buffer' ) ;
78
88
const {
79
89
constants : {
@@ -130,29 +140,15 @@ const {
130
140
markAsUntransferable,
131
141
addBufferPrototypeMethods,
132
142
createUnsafeBuffer,
143
+ asciiWrite,
144
+ latin1Write,
145
+ utf8Write,
133
146
} = require ( 'internal/buffer' ) ;
134
147
135
148
FastBuffer . prototype . constructor = Buffer ;
136
149
Buffer . prototype = FastBuffer . prototype ;
137
150
addBufferPrototypeMethods ( Buffer . prototype ) ;
138
151
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
-
156
152
const constants = ObjectDefineProperties ( { } , {
157
153
MAX_LENGTH : {
158
154
__proto__ : null ,
@@ -651,44 +647,44 @@ const encodingOps = {
651
647
encoding : 'utf8' ,
652
648
encodingVal : encodingsMap . utf8 ,
653
649
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 ,
656
652
indexOf : ( buf , val , byteOffset , dir ) =>
657
653
indexOfString ( buf , val , byteOffset , encodingsMap . utf8 , dir ) ,
658
654
} ,
659
655
ucs2 : {
660
656
encoding : 'ucs2' ,
661
657
encodingVal : encodingsMap . utf16le ,
662
658
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 ,
665
661
indexOf : ( buf , val , byteOffset , dir ) =>
666
662
indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
667
663
} ,
668
664
utf16le : {
669
665
encoding : 'utf16le' ,
670
666
encodingVal : encodingsMap . utf16le ,
671
667
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 ,
674
670
indexOf : ( buf , val , byteOffset , dir ) =>
675
671
indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
676
672
} ,
677
673
latin1 : {
678
674
encoding : 'latin1' ,
679
675
encodingVal : encodingsMap . latin1 ,
680
676
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 ,
683
679
indexOf : ( buf , val , byteOffset , dir ) =>
684
680
indexOfString ( buf , val , byteOffset , encodingsMap . latin1 , dir ) ,
685
681
} ,
686
682
ascii : {
687
683
encoding : 'ascii' ,
688
684
encodingVal : encodingsMap . ascii ,
689
685
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 ,
692
688
indexOf : ( buf , val , byteOffset , dir ) =>
693
689
indexOfBuffer ( buf ,
694
690
fromStringFast ( val , encodingOps . ascii ) ,
@@ -700,8 +696,8 @@ const encodingOps = {
700
696
encoding : 'base64' ,
701
697
encodingVal : encodingsMap . base64 ,
702
698
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 ,
705
701
indexOf : ( buf , val , byteOffset , dir ) =>
706
702
indexOfBuffer ( buf ,
707
703
fromStringFast ( val , encodingOps . base64 ) ,
@@ -713,9 +709,8 @@ const encodingOps = {
713
709
encoding : 'base64url' ,
714
710
encodingVal : encodingsMap . base64url ,
715
711
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 ,
719
714
indexOf : ( buf , val , byteOffset , dir ) =>
720
715
indexOfBuffer ( buf ,
721
716
fromStringFast ( val , encodingOps . base64url ) ,
@@ -727,8 +722,8 @@ const encodingOps = {
727
722
encoding : 'hex' ,
728
723
encodingVal : encodingsMap . hex ,
729
724
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 ,
732
727
indexOf : ( buf , val , byteOffset , dir ) =>
733
728
indexOfBuffer ( buf ,
734
729
fromStringFast ( val , encodingOps . hex ) ,
@@ -853,7 +848,7 @@ Buffer.prototype.copy =
853
848
// to their upper/lower bounds if the value passed is out of range.
854
849
Buffer . prototype . toString = function toString ( encoding , start , end ) {
855
850
if ( arguments . length === 0 ) {
856
- return FunctionPrototypeCall ( utf8Slice , this , 0 , this . length ) ;
851
+ return utf8Slice ( this , 0 , this . length ) ;
857
852
}
858
853
859
854
const len = this . length ;
@@ -874,7 +869,7 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
874
869
return '' ;
875
870
876
871
if ( encoding === undefined )
877
- return FunctionPrototypeCall ( utf8Slice , this , start , end ) ;
872
+ return utf8Slice ( this , start , end ) ;
878
873
879
874
const ops = getEncodingOps ( encoding ) ;
880
875
if ( ops === undefined )
@@ -905,7 +900,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
905
900
const actualMax = MathMin ( max , this . length ) ;
906
901
const remaining = this . length - max ;
907
902
let str = StringPrototypeTrim ( RegExpPrototypeSymbolReplace (
908
- / ( .{ 2 } ) / g, FunctionPrototypeCall ( hexSlice , this , 0 , actualMax ) , '$1 ' ) ) ;
903
+ / ( .{ 2 } ) / g, hexSlice ( this , 0 , actualMax ) , '$1 ' ) ) ;
909
904
if ( remaining > 0 )
910
905
str += ` ... ${ remaining } more byte${ remaining > 1 ? 's' : '' } ` ;
911
906
// Inspect special properties as well, if possible.
@@ -1129,7 +1124,7 @@ function _fill(buf, value, offset, end, encoding) {
1129
1124
Buffer . prototype . write = function write ( string , offset , length , encoding ) {
1130
1125
// Buffer#write(string);
1131
1126
if ( offset === undefined ) {
1132
- return FunctionPrototypeCall ( utf8Write , this , string , 0 , this . length ) ;
1127
+ return utf8Write ( this , string , 0 , this . length ) ;
1133
1128
}
1134
1129
// Buffer#write(string, encoding)
1135
1130
if ( length === undefined && typeof offset === 'string' ) {
@@ -1156,9 +1151,9 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
1156
1151
}
1157
1152
1158
1153
if ( ! encoding || encoding === 'utf8' )
1159
- return FunctionPrototypeCall ( utf8Write , this , string , offset , length ) ;
1154
+ return utf8Write ( this , string , offset , length ) ;
1160
1155
if ( encoding === 'ascii' )
1161
- return FunctionPrototypeCall ( asciiWrite , this , string , offset , length ) ;
1156
+ return asciiWrite ( this , string , offset , length ) ;
1162
1157
1163
1158
const ops = getEncodingOps ( encoding ) ;
1164
1159
if ( ops === undefined )
0 commit comments