MCPcopy Index your code
hub / github.com/nodejs/node / fromStringFast

Function fromStringFast

lib/buffer.js:479–504  ·  view source on GitHub ↗
(string, ops)

Source from the content-addressed store, hash-verified

477}
478
479function fromStringFast(string, ops) {
480 const maxLength = Buffer.poolSize >>> 1;
481
482 let length = string.length; // Min length
483
484 if (length >= maxLength)
485 return createFromString(string, ops);
486
487 length *= 4; // Max length (4 bytes per character)
488
489 if (length >= maxLength)
490 length = ops.byteLength(string); // Actual length
491
492 if (length >= maxLength)
493 return createFromString(string, ops, length);
494
495 if (length > (poolSize - poolOffset))
496 createPool();
497
498 const actual = ops.write(allocBuffer, string, poolOffset, length);
499 const b = new FastBuffer(allocPool, poolOffset, actual);
500
501 poolOffset += actual;
502 alignPool();
503 return b;
504}
505
506function createFromString(string, ops, length = ops.byteLength(string)) {
507 const buf = Buffer.allocUnsafeSlow(length);

Callers 2

fromStringFunction · 0.85
buffer.jsFile · 0.85

Calls 4

createFromStringFunction · 0.85
createPoolFunction · 0.85
alignPoolFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…