File tree 1 file changed +7
-2
lines changed
1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -442,21 +442,26 @@ function allocate(size) {
442
442
}
443
443
444
444
function fromStringFast ( string , ops ) {
445
- const length = ops . byteLength ( string ) ;
445
+ let length = string . length * 4 ; // max utf8 byte length
446
+
447
+ if ( length >= ( Buffer . poolSize >>> 1 ) )
448
+ length = ops . byteLength ( string ) ;
446
449
447
450
if ( length >= ( Buffer . poolSize >>> 1 ) )
448
451
return createFromString ( string , ops . encodingVal ) ;
449
452
450
453
if ( length > ( poolSize - poolOffset ) )
451
454
createPool ( ) ;
455
+
452
456
let b = new FastBuffer ( allocPool , poolOffset , length ) ;
453
457
const actual = ops . write ( b , string , 0 , length ) ;
454
458
if ( actual !== length ) {
455
- // byteLength() may overestimate. That's a rare case, though.
456
459
b = new FastBuffer ( allocPool , poolOffset , actual ) ;
457
460
}
461
+
458
462
poolOffset += actual ;
459
463
alignPool ( ) ;
464
+
460
465
return b ;
461
466
}
462
467
You can’t perform that action at this time.
0 commit comments