diff options
author | Tim Caswell <tim@creationix.com> | 2010-04-12 11:57:24 -0500 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-04-12 10:34:35 -0700 |
commit | 62d9852c3d6ed32825abfd79645c72a66fb00e6f (patch) | |
tree | 1993709c501253131dd04f9e8e0a7fe31f5bd893 /lib/querystring.js | |
parent | b7441040f87ff5e0e7b4575852996b6a64e0ea8f (diff) | |
download | nodejs-62d9852c3d6ed32825abfd79645c72a66fb00e6f.tar.gz nodejs-62d9852c3d6ed32825abfd79645c72a66fb00e6f.tar.bz2 nodejs-62d9852c3d6ed32825abfd79645c72a66fb00e6f.zip |
Replace slow and broken for..in loops with faster for loops over the keys.
Diffstat (limited to 'lib/querystring.js')
-rw-r--r-- | lib/querystring.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/querystring.js b/lib/querystring.js index 5220b53ae..83e0a0f85 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -55,9 +55,11 @@ QueryString.stringify = function (obj, sep, eq, name) { var s = []; var begin = name ? name + '[' : ''; var end = name ? ']' : ''; - for (var i in obj) if (obj.hasOwnProperty(i)) { - var n = begin + i + end; - s.push(QueryString.stringify(obj[i], sep, eq, n)); + var keys = Object.keys(obj); + for (var i = 0, l = keys.length; i < l; i++) { + var key = keys[i]; + var n = begin + key + end; + s.push(QueryString.stringify(obj[key], sep, eq, n)); } stack.pop(); @@ -138,10 +140,14 @@ function mergeParams (params, addition) { }; // Merge two *objects* together. If this is called, we've already ruled -// out the simple cases, and need to do the for-in business. +// out the simple cases, and need to do a loop. function mergeObjects (params, addition) { - for (var i in addition) if (i && addition.hasOwnProperty(i)) { - params[i] = mergeParams(params[i], addition[i]); + var keys = Object.keys(addition); + for (var i = 0, l = keys.length; i < l; i++) { + var key = keys[i]; + if (key) { + params[key] = mergeParams(params[key], addition[key]); + } } return params; }; |