@@ -35,12 +35,20 @@ const {
35
35
ObjectDefineProperties,
36
36
ObjectDefineProperty,
37
37
ObjectGetOwnPropertyDescriptor,
38
- ObjectGetPrototypeOf,
39
38
ObjectSetPrototypeOf,
39
+ StringPrototypeCharCodeAt,
40
+ StringPrototypeReplace,
41
+ StringPrototypeSlice,
42
+ StringPrototypeToLowerCase,
43
+ StringPrototypeTrim,
40
44
SymbolSpecies,
41
45
SymbolToPrimitive,
46
+ TypedArrayPrototype,
47
+ TypedArrayPrototypeFill,
48
+ TypedArrayPrototypeSet,
42
49
Uint8Array,
43
50
Uint8ArrayPrototype,
51
+ uncurryThis,
44
52
} = primordials ;
45
53
46
54
const {
@@ -109,12 +117,9 @@ const {
109
117
addBufferPrototypeMethods
110
118
} = require ( 'internal/buffer' ) ;
111
119
112
- const TypedArrayPrototype = ObjectGetPrototypeOf ( Uint8ArrayPrototype ) ;
113
-
114
- const TypedArrayProto_byteLength =
115
- ObjectGetOwnPropertyDescriptor ( TypedArrayPrototype ,
116
- 'byteLength' ) . get ;
117
- const TypedArrayFill = TypedArrayPrototype . fill ;
120
+ const TypedArrayProto_byteLength = uncurryThis (
121
+ ObjectGetOwnPropertyDescriptor ( TypedArrayPrototype ,
122
+ 'byteLength' ) . get ) ;
118
123
119
124
FastBuffer . prototype . constructor = Buffer ;
120
125
Buffer . prototype = FastBuffer . prototype ;
@@ -262,7 +267,7 @@ function _copyActual(source, target, targetStart, sourceStart, sourceEnd) {
262
267
if ( sourceStart !== 0 || sourceEnd < source . length )
263
268
source = new Uint8Array ( source . buffer , source . byteOffset + sourceStart , nb ) ;
264
269
265
- target . set ( source , targetStart ) ;
270
+ TypedArrayPrototypeSet ( target , source , targetStart ) ;
266
271
267
272
return nb ;
268
273
}
@@ -496,7 +501,7 @@ function fromArrayLike(obj) {
496
501
if ( obj . length > ( poolSize - poolOffset ) )
497
502
createPool ( ) ;
498
503
const b = new FastBuffer ( allocPool , poolOffset , obj . length ) ;
499
- b . set ( obj , 0 ) ;
504
+ TypedArrayPrototypeSet ( b , obj , 0 ) ;
500
505
poolOffset += obj . length ;
501
506
alignPool ( ) ;
502
507
return b ;
@@ -582,17 +587,17 @@ Buffer.concat = function concat(list, length) {
582
587
// Zero-fill the remaining bytes if the specified `length` was more than
583
588
// the actual total length, i.e. if we have some remaining allocated bytes
584
589
// there were not initialized.
585
- TypedArrayFill . call ( buffer , 0 , pos , length ) ;
590
+ TypedArrayPrototypeFill ( buffer , 0 , pos , length ) ;
586
591
}
587
592
588
593
return buffer ;
589
594
} ;
590
595
591
596
function base64ByteLength ( str , bytes ) {
592
597
// Handle padding
593
- if ( str . charCodeAt ( bytes - 1 ) === 0x3D )
598
+ if ( StringPrototypeCharCodeAt ( str , bytes - 1 ) === 0x3D )
594
599
bytes -- ;
595
- if ( bytes > 1 && str . charCodeAt ( bytes - 1 ) === 0x3D )
600
+ if ( bytes > 1 && StringPrototypeCharCodeAt ( str , bytes - 1 ) === 0x3D )
596
601
bytes -- ;
597
602
598
603
// Base64 ratio: 3/4
@@ -682,38 +687,40 @@ function getEncodingOps(encoding) {
682
687
case 4 :
683
688
if ( encoding === 'utf8' ) return encodingOps . utf8 ;
684
689
if ( encoding === 'ucs2' ) return encodingOps . ucs2 ;
685
- encoding = encoding . toLowerCase ( ) ;
690
+ encoding = StringPrototypeToLowerCase ( encoding ) ;
686
691
if ( encoding === 'utf8' ) return encodingOps . utf8 ;
687
692
if ( encoding === 'ucs2' ) return encodingOps . ucs2 ;
688
693
break ;
689
694
case 5 :
690
695
if ( encoding === 'utf-8' ) return encodingOps . utf8 ;
691
696
if ( encoding === 'ascii' ) return encodingOps . ascii ;
692
697
if ( encoding === 'ucs-2' ) return encodingOps . ucs2 ;
693
- encoding = encoding . toLowerCase ( ) ;
698
+ encoding = StringPrototypeToLowerCase ( encoding ) ;
694
699
if ( encoding === 'utf-8' ) return encodingOps . utf8 ;
695
700
if ( encoding === 'ascii' ) return encodingOps . ascii ;
696
701
if ( encoding === 'ucs-2' ) return encodingOps . ucs2 ;
697
702
break ;
698
703
case 7 :
699
- if ( encoding === 'utf16le' || encoding . toLowerCase ( ) === 'utf16le' )
704
+ if ( encoding === 'utf16le' ||
705
+ StringPrototypeToLowerCase ( encoding ) === 'utf16le' )
700
706
return encodingOps . utf16le ;
701
707
break ;
702
708
case 8 :
703
- if ( encoding === 'utf-16le' || encoding . toLowerCase ( ) === 'utf-16le' )
709
+ if ( encoding === 'utf-16le' ||
710
+ StringPrototypeToLowerCase ( encoding ) === 'utf-16le' )
704
711
return encodingOps . utf16le ;
705
712
break ;
706
713
case 6 :
707
714
if ( encoding === 'latin1' || encoding === 'binary' )
708
715
return encodingOps . latin1 ;
709
716
if ( encoding === 'base64' ) return encodingOps . base64 ;
710
- encoding = encoding . toLowerCase ( ) ;
717
+ encoding = StringPrototypeToLowerCase ( encoding ) ;
711
718
if ( encoding === 'latin1' || encoding === 'binary' )
712
719
return encodingOps . latin1 ;
713
720
if ( encoding === 'base64' ) return encodingOps . base64 ;
714
721
break ;
715
722
case 3 :
716
- if ( encoding === 'hex' || encoding . toLowerCase ( ) === 'hex' )
723
+ if ( encoding === 'hex' || StringPrototypeToLowerCase ( encoding ) === 'hex' )
717
724
return encodingOps . hex ;
718
725
break ;
719
726
}
@@ -826,7 +833,8 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
826
833
const max = INSPECT_MAX_BYTES ;
827
834
const actualMax = MathMin ( max , this . length ) ;
828
835
const remaining = this . length - max ;
829
- let str = this . hexSlice ( 0 , actualMax ) . replace ( / ( .{ 2 } ) / g, '$1 ' ) . trim ( ) ;
836
+ let str = StringPrototypeTrim ( StringPrototypeReplace (
837
+ this . hexSlice ( 0 , actualMax ) , / ( .{ 2 } ) / g, '$1 ' ) ) ;
830
838
if ( remaining > 0 )
831
839
str += ` ... ${ remaining } more byte${ remaining > 1 ? 's' : '' } ` ;
832
840
// Inspect special properties as well, if possible.
@@ -843,11 +851,11 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
843
851
str += ', ' ;
844
852
// '[Object: null prototype] {'.length === 26
845
853
// This is guarded with a test.
846
- str += utilInspect ( obj , {
854
+ str += StringPrototypeSlice ( utilInspect ( obj , {
847
855
...ctx ,
848
856
breakLength : Infinity ,
849
857
compact : true
850
- } ) . slice ( 27 , - 2 ) ;
858
+ } ) , 27 , - 2 ) ;
851
859
}
852
860
}
853
861
return `<${ this . constructor . name } ${ str } >` ;
@@ -991,12 +999,12 @@ function _fill(buf, value, offset, end, encoding) {
991
999
} else if ( value . length === 1 ) {
992
1000
// Fast path: If `value` fits into a single byte, use that numeric value.
993
1001
if ( normalizedEncoding === 'utf8' ) {
994
- const code = value . charCodeAt ( 0 ) ;
1002
+ const code = StringPrototypeCharCodeAt ( value , 0 ) ;
995
1003
if ( code < 128 ) {
996
1004
value = code ;
997
1005
}
998
1006
} else if ( normalizedEncoding === 'latin1' ) {
999
- value = value . charCodeAt ( 0 ) ;
1007
+ value = StringPrototypeCharCodeAt ( value , 0 ) ;
1000
1008
}
1001
1009
}
1002
1010
} else {
@@ -1021,12 +1029,12 @@ function _fill(buf, value, offset, end, encoding) {
1021
1029
1022
1030
if ( typeof value === 'number' ) {
1023
1031
// OOB check
1024
- const byteLen = TypedArrayProto_byteLength . call ( buf ) ;
1032
+ const byteLen = TypedArrayProto_byteLength ( buf ) ;
1025
1033
const fillLength = end - offset ;
1026
1034
if ( offset > end || fillLength + offset > byteLen )
1027
1035
throw new ERR_BUFFER_OUT_OF_BOUNDS ( ) ;
1028
1036
1029
- TypedArrayFill . call ( buf , value , offset , end ) ;
1037
+ TypedArrayPrototypeFill ( buf , value , offset , end ) ;
1030
1038
} else {
1031
1039
const res = bindingFill ( buf , value , offset , end , encoding ) ;
1032
1040
if ( res < 0 ) {
0 commit comments