From 9c655ac75dd78c909b1f713d72d85da043c57673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Fri, 24 Oct 2025 23:03:32 +0200 Subject: [PATCH] buffer: add early return for zero-length concat calls --- benchmark/buffers/buffer-concat.js | 2 +- lib/buffer.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/benchmark/buffers/buffer-concat.js b/benchmark/buffers/buffer-concat.js index 26edc649d8d349..51704978872940 100644 --- a/benchmark/buffers/buffer-concat.js +++ b/benchmark/buffers/buffer-concat.js @@ -3,7 +3,7 @@ const common = require('../common.js'); const bench = common.createBenchmark(main, { pieces: [4, 16], - pieceSize: [1, 16, 256], + pieceSize: [0, 1, 16, 256], withTotalLength: [0, 1], n: [8e5], }); diff --git a/lib/buffer.js b/lib/buffer.js index c9f45d333886d3..3148a6b4e4d9d3 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -590,6 +590,9 @@ Buffer.concat = function concat(list, length) { validateOffset(length, 'length'); } + if (length === 0) + return new FastBuffer(); + const buffer = Buffer.allocUnsafe(length); let pos = 0; for (let i = 0; i < list.length; i++) {