Skip to content

Commit

Permalink
util: add fast internal array join method
Browse files Browse the repository at this point in the history
PR-URL: #14881
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
BridgeAR authored and jasnell committed Sep 20, 2017
1 parent ba9012d commit 5394458
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -265,6 +279,7 @@ module.exports = {
normalizeEncoding,
objectToString,
promisify,
join,

// Symbol used to customize promisify conversion
customPromisifyArgs: kCustomPromisifyArgsSymbol,
Expand Down

0 comments on commit 5394458

Please sign in to comment.