@@ -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,
@@ -73,6 +72,17 @@ const {
73
72
kStringMaxLength,
74
73
atob : _atob ,
75
74
btoa : _btoa ,
75
+ asciiSlice,
76
+ base64Slice,
77
+ base64urlSlice,
78
+ latin1Slice,
79
+ hexSlice,
80
+ ucs2Slice,
81
+ utf8Slice,
82
+ base64Write,
83
+ base64urlWrite,
84
+ hexWrite,
85
+ ucs2Write,
76
86
} = internalBinding ( 'buffer' ) ;
77
87
const {
78
88
constants : {
@@ -128,29 +138,15 @@ const {
128
138
markAsUntransferable,
129
139
addBufferPrototypeMethods,
130
140
createUnsafeBuffer,
141
+ asciiWrite,
142
+ latin1Write,
143
+ utf8Write,
131
144
} = require ( 'internal/buffer' ) ;
132
145
133
146
FastBuffer . prototype . constructor = Buffer ;
134
147
Buffer . prototype = FastBuffer . prototype ;
135
148
addBufferPrototypeMethods ( Buffer . prototype ) ;
136
149
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
-
154
150
const constants = ObjectDefineProperties ( { } , {
155
151
MAX_LENGTH : {
156
152
__proto__ : null ,
@@ -639,44 +635,44 @@ const encodingOps = {
639
635
encoding : 'utf8' ,
640
636
encodingVal : encodingsMap . utf8 ,
641
637
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 ,
644
640
indexOf : ( buf , val , byteOffset , dir ) =>
645
641
indexOfString ( buf , val , byteOffset , encodingsMap . utf8 , dir ) ,
646
642
} ,
647
643
ucs2 : {
648
644
encoding : 'ucs2' ,
649
645
encodingVal : encodingsMap . utf16le ,
650
646
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 ,
653
649
indexOf : ( buf , val , byteOffset , dir ) =>
654
650
indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
655
651
} ,
656
652
utf16le : {
657
653
encoding : 'utf16le' ,
658
654
encodingVal : encodingsMap . utf16le ,
659
655
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 ,
662
658
indexOf : ( buf , val , byteOffset , dir ) =>
663
659
indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
664
660
} ,
665
661
latin1 : {
666
662
encoding : 'latin1' ,
667
663
encodingVal : encodingsMap . latin1 ,
668
664
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 ,
671
667
indexOf : ( buf , val , byteOffset , dir ) =>
672
668
indexOfString ( buf , val , byteOffset , encodingsMap . latin1 , dir ) ,
673
669
} ,
674
670
ascii : {
675
671
encoding : 'ascii' ,
676
672
encodingVal : encodingsMap . ascii ,
677
673
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 ,
680
676
indexOf : ( buf , val , byteOffset , dir ) =>
681
677
indexOfBuffer ( buf ,
682
678
fromStringFast ( val , encodingOps . ascii ) ,
@@ -688,8 +684,8 @@ const encodingOps = {
688
684
encoding : 'base64' ,
689
685
encodingVal : encodingsMap . base64 ,
690
686
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 ,
693
689
indexOf : ( buf , val , byteOffset , dir ) =>
694
690
indexOfBuffer ( buf ,
695
691
fromStringFast ( val , encodingOps . base64 ) ,
@@ -701,9 +697,8 @@ const encodingOps = {
701
697
encoding : 'base64url' ,
702
698
encodingVal : encodingsMap . base64url ,
703
699
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 ,
707
702
indexOf : ( buf , val , byteOffset , dir ) =>
708
703
indexOfBuffer ( buf ,
709
704
fromStringFast ( val , encodingOps . base64url ) ,
@@ -715,8 +710,8 @@ const encodingOps = {
715
710
encoding : 'hex' ,
716
711
encodingVal : encodingsMap . hex ,
717
712
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 ,
720
715
indexOf : ( buf , val , byteOffset , dir ) =>
721
716
indexOfBuffer ( buf ,
722
717
fromStringFast ( val , encodingOps . hex ) ,
@@ -841,7 +836,7 @@ Buffer.prototype.copy =
841
836
// to their upper/lower bounds if the value passed is out of range.
842
837
Buffer . prototype . toString = function toString ( encoding , start , end ) {
843
838
if ( arguments . length === 0 ) {
844
- return FunctionPrototypeCall ( utf8Slice , this , 0 , this . length ) ;
839
+ return utf8Slice ( this , 0 , this . length ) ;
845
840
}
846
841
847
842
const len = this . length ;
@@ -862,7 +857,7 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
862
857
return '' ;
863
858
864
859
if ( encoding === undefined )
865
- return FunctionPrototypeCall ( utf8Slice , this , start , end ) ;
860
+ return utf8Slice ( this , start , end ) ;
866
861
867
862
const ops = getEncodingOps ( encoding ) ;
868
863
if ( ops === undefined )
@@ -893,7 +888,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
893
888
const actualMax = MathMin ( max , this . length ) ;
894
889
const remaining = this . length - max ;
895
890
let str = StringPrototypeTrim ( RegExpPrototypeSymbolReplace (
896
- / ( .{ 2 } ) / g, FunctionPrototypeCall ( hexSlice , this , 0 , actualMax ) , '$1 ' ) ) ;
891
+ / ( .{ 2 } ) / g, hexSlice ( this , 0 , actualMax ) , '$1 ' ) ) ;
897
892
if ( remaining > 0 )
898
893
str += ` ... ${ remaining } more byte${ remaining > 1 ? 's' : '' } ` ;
899
894
// Inspect special properties as well, if possible.
@@ -1117,7 +1112,7 @@ function _fill(buf, value, offset, end, encoding) {
1117
1112
Buffer . prototype . write = function write ( string , offset , length , encoding ) {
1118
1113
// Buffer#write(string);
1119
1114
if ( offset === undefined ) {
1120
- return FunctionPrototypeCall ( utf8Write , this , string , 0 , this . length ) ;
1115
+ return utf8Write ( this , string , 0 , this . length ) ;
1121
1116
}
1122
1117
// Buffer#write(string, encoding)
1123
1118
if ( length === undefined && typeof offset === 'string' ) {
@@ -1144,9 +1139,9 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
1144
1139
}
1145
1140
1146
1141
if ( ! encoding || encoding === 'utf8' )
1147
- return FunctionPrototypeCall ( utf8Write , this , string , offset , length ) ;
1142
+ return utf8Write ( this , string , offset , length ) ;
1148
1143
if ( encoding === 'ascii' )
1149
- return FunctionPrototypeCall ( asciiWrite , this , string , offset , length ) ;
1144
+ return asciiWrite ( this , string , offset , length ) ;
1150
1145
1151
1146
const ops = getEncodingOps ( encoding ) ;
1152
1147
if ( ops === undefined )
0 commit comments