File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -442,21 +442,26 @@ function allocate(size) {
442442}
443443
444444function 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 ) ;
446449
447450 if ( length >= ( Buffer . poolSize >>> 1 ) )
448451 return createFromString ( string , ops . encodingVal ) ;
449452
450453 if ( length > ( poolSize - poolOffset ) )
451454 createPool ( ) ;
455+
452456 let b = new FastBuffer ( allocPool , poolOffset , length ) ;
453457 const actual = ops . write ( b , string , 0 , length ) ;
454458 if ( actual !== length ) {
455- // byteLength() may overestimate. That's a rare case, though.
456459 b = new FastBuffer ( allocPool , poolOffset , actual ) ;
457460 }
461+
458462 poolOffset += actual ;
459463 alignPool ( ) ;
464+
460465 return b ;
461466}
462467
You can’t perform that action at this time.
0 commit comments