(string, ops)
| 477 | } |
| 478 | |
| 479 | function 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 | |
| 506 | function createFromString(string, ops, length = ops.byteLength(string)) { |
| 507 | const buf = Buffer.allocUnsafeSlow(length); |
no test coverage detected
searching dependent graphs…