mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
buffer: improve from() performance
PR-URL: https://github.com/nodejs/node/pull/31615 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
2 files changed
+51
-32
No files matched your search
+13
-16
@@ -452,14 +452,6 @@ function fromString(string, encoding) {
|
||||
return fromStringFast(string, ops);
|
||||
}
|
||||
|
||||
function fromArrayLike(obj) {
|
||||
const length = obj.length;
|
||||
const b = allocate(length);
|
||||
for (let i = 0; i < length; i++)
|
||||
b[i] = obj[i];
|
||||
return b;
|
||||
}
|
||||
|
||||
function fromArrayBuffer(obj, byteOffset, length) {
|
||||
// Convert byteOffset to integer
|
||||
if (byteOffset === undefined) {
|
||||
@@ -491,17 +483,22 @@ function fromArrayBuffer(obj, byteOffset, length) {
|
||||
return new FastBuffer(obj, byteOffset, length);
|
||||
}
|
||||
|
||||
function fromObject(obj) {
|
||||
if (isUint8Array(obj)) {
|
||||
const b = allocate(obj.length);
|
||||
|
||||
if (b.length === 0)
|
||||
return b;
|
||||
|
||||
_copy(obj, b, 0, 0, obj.length);
|
||||
function fromArrayLike(obj) {
|
||||
if (obj.length <= 0)
|
||||
return new FastBuffer();
|
||||
if (obj.length < (Buffer.poolSize >>> 1)) {
|
||||
if (obj.length > (poolSize - poolOffset))
|
||||
createPool();
|
||||
const b = new FastBuffer(allocPool, poolOffset, obj.length);
|
||||
b.set(obj, 0);
|
||||
poolOffset += obj.length;
|
||||
alignPool();
|
||||
return b;
|
||||
}
|
||||
return new FastBuffer(obj);
|
||||
}
|
||||
|
||||
function fromObject(obj) {
|
||||
if (obj.length !== undefined || isAnyArrayBuffer(obj.buffer)) {
|
||||
if (typeof obj.length !== 'number') {
|
||||
return new FastBuffer();
|
||||
|
||||
Reference in new issue
Block a user