lib: improved forEach object performance
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
parent
86bb7fa5cd
commit
176f0bd3df
@ -1367,7 +1367,9 @@ Interface.prototype.setBreakpoint = function(script, line,
|
|||||||
// setBreakpoint('scriptname')
|
// setBreakpoint('scriptname')
|
||||||
if (script != +script && !this.client.scripts[script]) {
|
if (script != +script && !this.client.scripts[script]) {
|
||||||
var scripts = this.client.scripts;
|
var scripts = this.client.scripts;
|
||||||
Object.keys(scripts).forEach(function(id) {
|
var keys = Object.keys(scripts);
|
||||||
|
for (var v = 0; v < keys.length; v++) {
|
||||||
|
var id = keys[v];
|
||||||
if (scripts[id] &&
|
if (scripts[id] &&
|
||||||
scripts[id].name &&
|
scripts[id].name &&
|
||||||
scripts[id].name.indexOf(script) !== -1) {
|
scripts[id].name.indexOf(script) !== -1) {
|
||||||
@ -1376,7 +1378,7 @@ Interface.prototype.setBreakpoint = function(script, line,
|
|||||||
}
|
}
|
||||||
scriptId = id;
|
scriptId = id;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} else {
|
} else {
|
||||||
scriptId = script;
|
scriptId = script;
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,9 @@ Agent.prototype.removeSocket = function(s, options) {
|
|||||||
if (s.destroyed)
|
if (s.destroyed)
|
||||||
sets.push(this.freeSockets);
|
sets.push(this.freeSockets);
|
||||||
|
|
||||||
sets.forEach(function(sockets) {
|
for (var sk = 0; sk < sets.length; sk++) {
|
||||||
|
var sockets = sets[sk];
|
||||||
|
|
||||||
if (sockets[name]) {
|
if (sockets[name]) {
|
||||||
var index = sockets[name].indexOf(s);
|
var index = sockets[name].indexOf(s);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
@ -245,7 +247,8 @@ Agent.prototype.removeSocket = function(s, options) {
|
|||||||
delete sockets[name];
|
delete sockets[name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
if (this.requests[name] && this.requests[name].length) {
|
if (this.requests[name] && this.requests[name].length) {
|
||||||
debug('removeSocket, have a request, make a socket');
|
debug('removeSocket, have a request, make a socket');
|
||||||
var req = this.requests[name][0];
|
var req = this.requests[name][0];
|
||||||
@ -256,13 +259,16 @@ Agent.prototype.removeSocket = function(s, options) {
|
|||||||
|
|
||||||
Agent.prototype.destroy = function() {
|
Agent.prototype.destroy = function() {
|
||||||
var sets = [this.freeSockets, this.sockets];
|
var sets = [this.freeSockets, this.sockets];
|
||||||
sets.forEach(function(set) {
|
for (var s = 0; s < sets.length; s++) {
|
||||||
Object.keys(set).forEach(function(name) {
|
var set = sets[s];
|
||||||
set[name].forEach(function(socket) {
|
var keys = Object.keys(set);
|
||||||
socket.destroy();
|
for (var v = 0; v < keys.length; v++) {
|
||||||
});
|
var setName = set[keys[v]];
|
||||||
});
|
for (var n = 0; n < setName.length; n++) {
|
||||||
});
|
setName[n].destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.globalAgent = new Agent();
|
exports.globalAgent = new Agent();
|
||||||
|
@ -31,10 +31,12 @@ var Writable = require('_stream_writable');
|
|||||||
|
|
||||||
util.inherits(Duplex, Readable);
|
util.inherits(Duplex, Readable);
|
||||||
|
|
||||||
Object.keys(Writable.prototype).forEach(function(method) {
|
var keys = Object.keys(Writable.prototype);
|
||||||
|
for (var v = 0; v < keys.length; v++) {
|
||||||
|
var method = keys[v];
|
||||||
if (!Duplex.prototype[method])
|
if (!Duplex.prototype[method])
|
||||||
Duplex.prototype[method] = Writable.prototype[method];
|
Duplex.prototype[method] = Writable.prototype[method];
|
||||||
});
|
}
|
||||||
|
|
||||||
function Duplex(options) {
|
function Duplex(options) {
|
||||||
if (!(this instanceof Duplex))
|
if (!(this instanceof Duplex))
|
||||||
|
@ -44,9 +44,11 @@ function Console(stdout, stderr) {
|
|||||||
Object.defineProperty(this, '_times', prop);
|
Object.defineProperty(this, '_times', prop);
|
||||||
|
|
||||||
// bind the prototype functions to this Console instance
|
// bind the prototype functions to this Console instance
|
||||||
Object.keys(Console.prototype).forEach(function(k) {
|
var keys = Object.keys(Console.prototype);
|
||||||
|
for (var v = 0; v < keys.length; v++) {
|
||||||
|
var k = keys[v];
|
||||||
this[k] = this[k].bind(this);
|
this[k] = this[k].bind(this);
|
||||||
}, this);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.prototype.log = function() {
|
Console.prototype.log = function() {
|
||||||
|
24
lib/url.js
24
lib/url.js
@ -451,9 +451,11 @@ Url.prototype.resolveObject = function(relative) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var result = new Url();
|
var result = new Url();
|
||||||
Object.keys(this).forEach(function(k) {
|
var tkeys = Object.keys(this);
|
||||||
result[k] = this[k];
|
for (var tk = 0; tk < tkeys.length; tk++) {
|
||||||
}, this);
|
var tkey = tkeys[tk];
|
||||||
|
result[tkey] = this[tkey];
|
||||||
|
}
|
||||||
|
|
||||||
// hash is always overridden, no matter what.
|
// hash is always overridden, no matter what.
|
||||||
// even href="" will remove it.
|
// even href="" will remove it.
|
||||||
@ -468,10 +470,12 @@ Url.prototype.resolveObject = function(relative) {
|
|||||||
// hrefs like //foo/bar always cut to the protocol.
|
// hrefs like //foo/bar always cut to the protocol.
|
||||||
if (relative.slashes && !relative.protocol) {
|
if (relative.slashes && !relative.protocol) {
|
||||||
// take everything except the protocol from relative
|
// take everything except the protocol from relative
|
||||||
Object.keys(relative).forEach(function(k) {
|
var rkeys = Object.keys(relative);
|
||||||
if (k !== 'protocol')
|
for (var rk = 0; rk < rkeys.length; rk++) {
|
||||||
result[k] = relative[k];
|
var rkey = rkeys[rk];
|
||||||
});
|
if (rkey !== 'protocol')
|
||||||
|
result[rkey] = relative[rkey];
|
||||||
|
}
|
||||||
|
|
||||||
//urlParse appends trailing / to urls like http://www.example.com
|
//urlParse appends trailing / to urls like http://www.example.com
|
||||||
if (slashedProtocol[result.protocol] &&
|
if (slashedProtocol[result.protocol] &&
|
||||||
@ -493,9 +497,11 @@ Url.prototype.resolveObject = function(relative) {
|
|||||||
// because that's known to be hostless.
|
// because that's known to be hostless.
|
||||||
// anything else is assumed to be absolute.
|
// anything else is assumed to be absolute.
|
||||||
if (!slashedProtocol[relative.protocol]) {
|
if (!slashedProtocol[relative.protocol]) {
|
||||||
Object.keys(relative).forEach(function(k) {
|
var keys = Object.keys(relative);
|
||||||
|
for (var v = 0; v < keys.length; v++) {
|
||||||
|
var k = keys[v];
|
||||||
result[k] = relative[k];
|
result[k] = relative[k];
|
||||||
});
|
}
|
||||||
result.href = result.format();
|
result.href = result.format();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
16
lib/zlib.js
16
lib/zlib.js
@ -47,9 +47,11 @@ binding.Z_MAX_LEVEL = 9;
|
|||||||
binding.Z_DEFAULT_LEVEL = binding.Z_DEFAULT_COMPRESSION;
|
binding.Z_DEFAULT_LEVEL = binding.Z_DEFAULT_COMPRESSION;
|
||||||
|
|
||||||
// expose all the zlib constants
|
// expose all the zlib constants
|
||||||
Object.keys(binding).forEach(function(k) {
|
var bkeys = Object.keys(binding);
|
||||||
if (k.match(/^Z/)) exports[k] = binding[k];
|
for (var bk = 0; bk < bkeys.length; bk++) {
|
||||||
});
|
var bkey = bkeys[bk];
|
||||||
|
if (bkey.match(/^Z/)) exports[bkey] = binding[bkey];
|
||||||
|
}
|
||||||
|
|
||||||
// translation table for return codes.
|
// translation table for return codes.
|
||||||
exports.codes = {
|
exports.codes = {
|
||||||
@ -64,9 +66,11 @@ exports.codes = {
|
|||||||
Z_VERSION_ERROR: binding.Z_VERSION_ERROR
|
Z_VERSION_ERROR: binding.Z_VERSION_ERROR
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.keys(exports.codes).forEach(function(k) {
|
var ckeys = Object.keys(exports.codes);
|
||||||
exports.codes[exports.codes[k]] = k;
|
for (var ck = 0; ck < ckeys.length; ck++) {
|
||||||
});
|
var ckey = ckeys[ck];
|
||||||
|
exports.codes[exports.codes[ckey]] = ckey;
|
||||||
|
}
|
||||||
|
|
||||||
exports.Deflate = Deflate;
|
exports.Deflate = Deflate;
|
||||||
exports.Inflate = Inflate;
|
exports.Inflate = Inflate;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user