Skip to content

Commit 01652cc

Browse files
committed
util: add fast internal array join method
PR-URL: nodejs#14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 6bfc439 commit 01652cc

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

lib/internal/util.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,20 @@ function promisify(original) {
257257

258258
promisify.custom = kCustomPromisifiedSymbol;
259259

260+
// The build-in Array#join is slower in v8 6.0
261+
function join(output, separator) {
262+
var str = '';
263+
if (output.length !== 0) {
264+
for (var i = 0; i < output.length - 1; i++) {
265+
// It is faster not to use a template string here
266+
str += output[i];
267+
str += separator;
268+
}
269+
str += output[i];
270+
}
271+
return str;
272+
}
273+
260274
module.exports = {
261275
assertCrypto,
262276
cachedResult,
@@ -270,6 +284,7 @@ module.exports = {
270284
normalizeEncoding,
271285
objectToString,
272286
promisify,
287+
join,
273288

274289
// Symbol used to customize promisify conversion
275290
customPromisifyArgs: kCustomPromisifyArgsSymbol,

0 commit comments

Comments
 (0)