From 539445890b2df72d5fe6025b372e45f0f8a63075 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 21 Aug 2017 23:20:59 -0300 Subject: [PATCH] util: add fast internal array join method PR-URL: https://github.com/nodejs/node/pull/14881 Reviewed-By: Refael Ackermann Reviewed-By: Matteo Collina Reviewed-By: Benjamin Gruenbaum --- lib/internal/util.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/internal/util.js b/lib/internal/util.js index 113c0c66c0fe47..1a4e8d62477f2a 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -252,6 +252,20 @@ function promisify(orig) { promisify.custom = kCustomPromisifiedSymbol; +// The build-in Array#join is slower in v8 6.0 +function join(output, separator) { + var str = ''; + if (output.length !== 0) { + for (var i = 0; i < output.length - 1; i++) { + // It is faster not to use a template string here + str += output[i]; + str += separator; + } + str += output[i]; + } + return str; +} + module.exports = { assertCrypto, cachedResult, @@ -265,6 +279,7 @@ module.exports = { normalizeEncoding, objectToString, promisify, + join, // Symbol used to customize promisify conversion customPromisifyArgs: kCustomPromisifyArgsSymbol,