mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
buffer: improve concat() performance
PR-URL: https://github.com/nodejs/node/pull/31522 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
1 parent
32f63fcf0e
commit
2170259940
3 files changed
+30
-3
No files matched your search
+6
-3
@@ -238,6 +238,10 @@ function _copy(source, target, targetStart, sourceStart, sourceEnd) {
|
||||
sourceStart);
|
||||
}
|
||||
|
||||
return _copyActual(source, target, targetStart, sourceStart, sourceEnd);
|
||||
}
|
||||
|
||||
function _copyActual(source, target, targetStart, sourceStart, sourceEnd) {
|
||||
if (sourceEnd - sourceStart > target.length - targetStart)
|
||||
sourceEnd = sourceStart + target.length - targetStart;
|
||||
|
||||
@@ -568,8 +572,7 @@ Buffer.concat = function concat(list, length) {
|
||||
throw new ERR_INVALID_ARG_TYPE(
|
||||
`list[${i}]`, ['Buffer', 'Uint8Array'], list[i]);
|
||||
}
|
||||
_copy(buf, buffer, pos);
|
||||
pos += buf.length;
|
||||
pos += _copyActual(buf, buffer, pos, 0, buf.length);
|
||||
}
|
||||
|
||||
// Note: `length` is always equal to `buffer.length` at this point
|
||||
@@ -577,7 +580,7 @@ Buffer.concat = function concat(list, length) {
|
||||
// Zero-fill the remaining bytes if the specified `length` was more than
|
||||
// the actual total length, i.e. if we have some remaining allocated bytes
|
||||
// there were not initialized.
|
||||
buffer.fill(0, pos, length);
|
||||
TypedArrayFill.call(buffer, 0, pos, length);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
||||
Reference in new issue
Block a user