@@ -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' ) ;
7787const {
7888 constants : {
@@ -128,29 +138,15 @@ const {
128138 markAsUntransferable,
129139 addBufferPrototypeMethods,
130140 createUnsafeBuffer,
141+ asciiWrite,
142+ latin1Write,
143+ utf8Write,
131144} = require ( 'internal/buffer' ) ;
132145
133146FastBuffer . prototype . constructor = Buffer ;
134147Buffer . prototype = FastBuffer . prototype ;
135148addBufferPrototypeMethods ( 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-
154150const constants = ObjectDefineProperties ( { } , {
155151 MAX_LENGTH : {
156152 __proto__ : null ,
@@ -652,44 +648,44 @@ const encodingOps = {
652648 encoding : 'utf8' ,
653649 encodingVal : encodingsMap . utf8 ,
654650 byteLength : byteLengthUtf8 ,
655- write : ( buf , string , offset , len ) => FunctionPrototypeCall ( utf8Write , buf , string , offset , len ) ,
656- slice : ( buf , start , end ) => FunctionPrototypeCall ( utf8Slice , buf , start , end ) ,
651+ write : utf8Write ,
652+ slice : utf8Slice ,
657653 indexOf : ( buf , val , byteOffset , dir ) =>
658654 indexOfString ( buf , val , byteOffset , encodingsMap . utf8 , dir ) ,
659655 } ,
660656 ucs2 : {
661657 encoding : 'ucs2' ,
662658 encodingVal : encodingsMap . utf16le ,
663659 byteLength : ( string ) => string . length * 2 ,
664- write : ( buf , string , offset , len ) => FunctionPrototypeCall ( ucs2Write , buf , string , offset , len ) ,
665- slice : ( buf , start , end ) => FunctionPrototypeCall ( ucs2Slice , buf , start , end ) ,
660+ write : ucs2Write ,
661+ slice : ucs2Slice ,
666662 indexOf : ( buf , val , byteOffset , dir ) =>
667663 indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
668664 } ,
669665 utf16le : {
670666 encoding : 'utf16le' ,
671667 encodingVal : encodingsMap . utf16le ,
672668 byteLength : ( string ) => string . length * 2 ,
673- write : ( buf , string , offset , len ) => FunctionPrototypeCall ( ucs2Write , buf , string , offset , len ) ,
674- slice : ( buf , start , end ) => FunctionPrototypeCall ( ucs2Slice , buf , start , end ) ,
669+ write : ucs2Write ,
670+ slice : ucs2Slice ,
675671 indexOf : ( buf , val , byteOffset , dir ) =>
676672 indexOfString ( buf , val , byteOffset , encodingsMap . utf16le , dir ) ,
677673 } ,
678674 latin1 : {
679675 encoding : 'latin1' ,
680676 encodingVal : encodingsMap . latin1 ,
681677 byteLength : ( string ) => string . length ,
682- write : ( buf , string , offset , len ) => FunctionPrototypeCall ( latin1Write , buf , string , offset , len ) ,
683- slice : ( buf , start , end ) => FunctionPrototypeCall ( latin1Slice , buf , start , end ) ,
678+ write : latin1Write ,
679+ slice : latin1Slice ,
684680 indexOf : ( buf , val , byteOffset , dir ) =>
685681 indexOfString ( buf , val , byteOffset , encodingsMap . latin1 , dir ) ,
686682 } ,
687683 ascii : {
688684 encoding : 'ascii' ,
689685 encodingVal : encodingsMap . ascii ,
690686 byteLength : ( string ) => string . length ,
691- write : ( buf , string , offset , len ) => FunctionPrototypeCall ( asciiWrite , buf , string , offset , len ) ,
692- slice : ( buf , start , end ) => FunctionPrototypeCall ( asciiSlice , buf , start , end ) ,
687+ write : asciiWrite ,
688+ slice : asciiSlice ,
693689 indexOf : ( buf , val , byteOffset , dir ) =>
694690 indexOfBuffer ( buf ,
695691 fromStringFast ( val , encodingOps . ascii ) ,
@@ -701,8 +697,8 @@ const encodingOps = {
701697 encoding : 'base64' ,
702698 encodingVal : encodingsMap . base64 ,
703699 byteLength : ( string ) => base64ByteLength ( string , string . length ) ,
704- write : ( buf , string , offset , len ) => FunctionPrototypeCall ( base64Write , buf , string , offset , len ) ,
705- slice : ( buf , start , end ) => FunctionPrototypeCall ( base64Slice , buf , start , end ) ,
700+ write : base64Write ,
701+ slice : base64Slice ,
706702 indexOf : ( buf , val , byteOffset , dir ) =>
707703 indexOfBuffer ( buf ,
708704 fromStringFast ( val , encodingOps . base64 ) ,
@@ -714,9 +710,8 @@ const encodingOps = {
714710 encoding : 'base64url' ,
715711 encodingVal : encodingsMap . base64url ,
716712 byteLength : ( string ) => base64ByteLength ( string , string . length ) ,
717- write : ( buf , string , offset , len ) =>
718- FunctionPrototypeCall ( base64urlWrite , buf , string , offset , len ) ,
719- slice : ( buf , start , end ) => FunctionPrototypeCall ( base64urlSlice , buf , start , end ) ,
713+ write : base64urlWrite ,
714+ slice : base64urlSlice ,
720715 indexOf : ( buf , val , byteOffset , dir ) =>
721716 indexOfBuffer ( buf ,
722717 fromStringFast ( val , encodingOps . base64url ) ,
@@ -728,8 +723,8 @@ const encodingOps = {
728723 encoding : 'hex' ,
729724 encodingVal : encodingsMap . hex ,
730725 byteLength : ( string ) => string . length >>> 1 ,
731- write : ( buf , string , offset , len ) => FunctionPrototypeCall ( hexWrite , buf , string , offset , len ) ,
732- slice : ( buf , start , end ) => FunctionPrototypeCall ( hexSlice , buf , start , end ) ,
726+ write : hexWrite ,
727+ slice : hexSlice ,
733728 indexOf : ( buf , val , byteOffset , dir ) =>
734729 indexOfBuffer ( buf ,
735730 fromStringFast ( val , encodingOps . hex ) ,
@@ -854,7 +849,7 @@ Buffer.prototype.copy =
854849// to their upper/lower bounds if the value passed is out of range.
855850Buffer . prototype . toString = function toString ( encoding , start , end ) {
856851 if ( arguments . length === 0 ) {
857- return FunctionPrototypeCall ( utf8Slice , this , 0 , this . length ) ;
852+ return utf8Slice ( this , 0 , this . length ) ;
858853 }
859854
860855 const len = this . length ;
@@ -875,7 +870,7 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
875870 return '' ;
876871
877872 if ( encoding === undefined )
878- return FunctionPrototypeCall ( utf8Slice , this , start , end ) ;
873+ return utf8Slice ( this , start , end ) ;
879874
880875 const ops = getEncodingOps ( encoding ) ;
881876 if ( ops === undefined )
@@ -906,7 +901,7 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
906901 const actualMax = MathMin ( max , this . length ) ;
907902 const remaining = this . length - max ;
908903 let str = StringPrototypeTrim ( RegExpPrototypeSymbolReplace (
909- / ( .{ 2 } ) / g, FunctionPrototypeCall ( hexSlice , this , 0 , actualMax ) , '$1 ' ) ) ;
904+ / ( .{ 2 } ) / g, hexSlice ( this , 0 , actualMax ) , '$1 ' ) ) ;
910905 if ( remaining > 0 )
911906 str += ` ... ${ remaining } more byte${ remaining > 1 ? 's' : '' } ` ;
912907 // Inspect special properties as well, if possible.
@@ -1130,7 +1125,7 @@ function _fill(buf, value, offset, end, encoding) {
11301125Buffer . prototype . write = function write ( string , offset , length , encoding ) {
11311126 // Buffer#write(string);
11321127 if ( offset === undefined ) {
1133- return FunctionPrototypeCall ( utf8Write , this , string , 0 , this . length ) ;
1128+ return utf8Write ( this , string , 0 , this . length ) ;
11341129 }
11351130 // Buffer#write(string, encoding)
11361131 if ( length === undefined && typeof offset === 'string' ) {
@@ -1157,9 +1152,9 @@ Buffer.prototype.write = function write(string, offset, length, encoding) {
11571152 }
11581153
11591154 if ( ! encoding || encoding === 'utf8' )
1160- return FunctionPrototypeCall ( utf8Write , this , string , offset , length ) ;
1155+ return utf8Write ( this , string , offset , length ) ;
11611156 if ( encoding === 'ascii' )
1162- return FunctionPrototypeCall ( asciiWrite , this , string , offset , length ) ;
1157+ return asciiWrite ( this , string , offset , length ) ;
11631158
11641159 const ops = getEncodingOps ( encoding ) ;
11651160 if ( ops === undefined )
0 commit comments