buffer: speed up concat via TypedArray#set · nodejs/node@4810e4b · GitHub
Skip to content

Commit 4810e4b

Browse files
gurgundayaduh95
authored andcommitted
buffer: speed up concat via TypedArray#set
PR-URL: #60399 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent a38e2f5 commit 4810e4b

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

lib/buffer.js

Lines changed: 7 additions & 3 deletions

test/parallel/test-buffer-concat.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ assert.throws(() => {
7676
const random10 = common.hasCrypto ?
7777
require('crypto').randomBytes(10) :
7878
Buffer.alloc(10, 1);
79+
const derived18 = Buffer.alloc(18);
80+
for (let i = 0, j = 0; i < 18; i++) {
81+
if (i < 10)
82+
derived18[i] = random10[i];
83+
else
84+
derived18[i] = random10[j++];
85+
}
7986
const empty = Buffer.alloc(0);
8087

8188
assert.notDeepStrictEqual(random10, empty);
@@ -85,6 +92,7 @@ assert.deepStrictEqual(Buffer.concat([], 100), empty);
8592
assert.deepStrictEqual(Buffer.concat([random10], 0), empty);
8693
assert.deepStrictEqual(Buffer.concat([random10], 10), random10);
8794
assert.deepStrictEqual(Buffer.concat([random10, random10], 10), random10);
95+
assert.deepStrictEqual(Buffer.concat([random10, random10], 18), derived18);
8896
assert.deepStrictEqual(Buffer.concat([empty, random10]), random10);
8997
assert.deepStrictEqual(Buffer.concat([random10, empty, empty]), random10);
9098

test/parallel/test-buffer-copy.js

Lines changed: 17 additions & 0 deletions

0 commit comments

Comments
 (0)