Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'use strict';

var domain;
var spliceOne;

function EventEmitter() {
EventEmitter.init.call(this);
Expand Down Expand Up @@ -389,8 +390,11 @@ EventEmitter.prototype.removeListener =

if (position === 0)
list.shift();
else
else {
if (spliceOne === undefined)
spliceOne = require('internal/util').spliceOne;
spliceOne(list, position);
}

if (list.length === 1)
events[type] = list[0];
Expand Down Expand Up @@ -502,13 +506,6 @@ EventEmitter.prototype.eventNames = function eventNames() {
return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
};

// About 1.5x faster than the two-arg version of Array#splice().
function spliceOne(list, index) {
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
list[i] = list[k];
list.pop();
}

function arrayClone(arr, n) {
var copy = new Array(n);
for (var i = 0; i < n; ++i)
Expand Down
10 changes: 9 additions & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ function join(output, separator) {
return str;
}

// About 1.5x faster than the two-arg version of Array#splice().
function spliceOne(list, index) {
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
list[i] = list[k];
list.pop();
}

module.exports = {
assertCrypto,
cachedResult,
Expand All @@ -276,10 +283,11 @@ module.exports = {
filterDuplicateStrings,
getConstructorOf,
isError,
join,
normalizeEncoding,
objectToString,
promisify,
join,
spliceOne,

// Symbol used to customize promisify conversion
customPromisifyArgs: kCustomPromisifyArgsSymbol,
Expand Down
8 changes: 1 addition & 7 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const { toASCII } = process.binding('config').hasIntl ?
process.binding('icu') : require('punycode');

const { hexTable } = require('internal/querystring');
const { spliceOne } = require('internal/util');

// WHATWG URL implementation provided by internal/url
const {
Expand Down Expand Up @@ -948,13 +949,6 @@ Url.prototype.parseHost = function parseHost() {
if (host) this.hostname = host;
};

// About 1.5x faster than the two-arg version of Array#splice().
function spliceOne(list, index) {
for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
list[i] = list[k];
list.pop();
}

// These characters do not need escaping:
// ! - . _ ~
// ' ( ) * :
Expand Down