Skip to content
This repository was archived by the owner on Aug 31, 2018. It is now read-only.

Commit 2d31ac2

Browse files
starkwangaddaleax
authored andcommitted
lib: move duplicate spliceOne into internal/util
lib/url.js and lib/events.js are using the same spliceOne function. This change is to move it into the internal/util for avoiding duplicate code. PR-URL: nodejs/node#16221 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 3d33c14 commit 2d31ac2

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/internal/util.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ function join(output, separator) {
271271
return str;
272272
}
273273

274+
// About 1.5x faster than the two-arg version of Array#splice().
275+
function spliceOne(list, index) {
276+
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
277+
list[i] = list[k];
278+
list.pop();
279+
}
280+
274281
module.exports = {
275282
assertCrypto,
276283
cachedResult,
@@ -281,10 +288,11 @@ module.exports = {
281288
filterDuplicateStrings,
282289
getConstructorOf,
283290
isError,
291+
join,
284292
normalizeEncoding,
285293
objectToString,
286294
promisify,
287-
join,
295+
spliceOne,
288296

289297
// Symbol used to customize promisify conversion
290298
customPromisifyArgs: kCustomPromisifyArgsSymbol,

lib/url.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const { hexTable } = require('internal/querystring');
2828

2929
const errors = require('internal/errors');
3030

31+
const { spliceOne } = require('internal/util');
32+
3133
// WHATWG URL implementation provided by internal/url
3234
const {
3335
URL,
@@ -950,13 +952,6 @@ Url.prototype.parseHost = function parseHost() {
950952
if (host) this.hostname = host;
951953
};
952954

953-
// About 1.5x faster than the two-arg version of Array#splice().
954-
function spliceOne(list, index) {
955-
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
956-
list[i] = list[k];
957-
list.pop();
958-
}
959-
960955
// These characters do not need escaping:
961956
// ! - . _ ~
962957
// ' ( ) * :

0 commit comments

Comments
 (0)