Skip to content

Commit 5394458

Browse files
BridgeARjasnell
authored andcommitted
util: add fast internal array join method
PR-URL: #14881 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent ba9012d commit 5394458

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/internal/util.js

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

253253
promisify.custom = kCustomPromisifiedSymbol;
254254

255+
// The build-in Array#join is slower in v8 6.0
256+
function join(output, separator) {
257+
var str = '';
258+
if (output.length !== 0) {
259+
for (var i = 0; i < output.length - 1; i++) {
260+
// It is faster not to use a template string here
261+
str += output[i];
262+
str += separator;
263+
}
264+
str += output[i];
265+
}
266+
return str;
267+
}
268+
255269
module.exports = {
256270
assertCrypto,
257271
cachedResult,
@@ -265,6 +279,7 @@ module.exports = {
265279
normalizeEncoding,
266280
objectToString,
267281
promisify,
282+
join,
268283

269284
// Symbol used to customize promisify conversion
270285
customPromisifyArgs: kCustomPromisifyArgsSymbol,

0 commit comments

Comments
 (0)