diff options
author | Brian White <mscdex@mscdex.net> | 2016-12-20 02:53:47 -0500 |
---|---|---|
committer | Brian White <mscdex@mscdex.net> | 2016-12-29 14:19:14 -0500 |
commit | 4d7531de247339692aced0f9c5643d458e80fc6e (patch) | |
tree | 46f471663d167952770e75e75a4e44e3a225a135 /lib/_http_outgoing.js | |
parent | af74e72a9f163659865f835d313f5e532956e077 (diff) | |
download | android-node-v8-4d7531de247339692aced0f9c5643d458e80fc6e.tar.gz android-node-v8-4d7531de247339692aced0f9c5643d458e80fc6e.tar.bz2 android-node-v8-4d7531de247339692aced0f9c5643d458e80fc6e.zip |
http: optimize headers iteration
This commit uses instanceof instead of Array.isArray() for faster
type checking and avoids calling Object.keys() when the headers are
stored as a 2D array instead of a plain object.
PR-URL: https://github.com/nodejs/node/pull/6533
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'lib/_http_outgoing.js')
-rw-r--r-- | lib/_http_outgoing.js | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 262b1d9f87..67a8d6f8bb 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -209,23 +209,31 @@ function _storeHeader(firstLine, headers) { messageHeader: firstLine }; - if (headers) { - var keys = Object.keys(headers); - var isArray = Array.isArray(headers); - var field, value; - - for (var i = 0, l = keys.length; i < l; i++) { - var key = keys[i]; - if (isArray) { - field = headers[key][0]; - value = headers[key][1]; + var i; + var j; + var field; + var value; + if (headers instanceof Array) { + for (i = 0; i < headers.length; ++i) { + field = headers[i][0]; + value = headers[i][1]; + + if (value instanceof Array) { + for (j = 0; j < value.length; j++) { + storeHeader(this, state, field, value[j]); + } } else { - field = key; - value = headers[key]; + storeHeader(this, state, field, value); } + } + } else if (headers) { + var keys = Object.keys(headers); + for (i = 0; i < keys.length; ++i) { + field = keys[i]; + value = headers[field]; - if (Array.isArray(value)) { - for (var j = 0; j < value.length; j++) { + if (value instanceof Array) { + for (j = 0; j < value.length; j++) { storeHeader(this, state, field, value[j]); } } else { |