Skip to content

Commit

Permalink
http2: rename counter in mapToHeaders inner loop
Browse files Browse the repository at this point in the history
This change is to prevent potential bugs - e.g., someone might
automatically use the variable `k` instead of `key`, that is used in
vicinity of this loop.
Also changed postincrement to preincrement in iteration steps. It is
probably done by the optimizer anyway, but otherwise it will save an
opcode each iteration. And it is a good practice.

PR-URL: #32012
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
mkrawczuk authored and targos committed Apr 22, 2020
1 parent 776905e commit e54eb46
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/internal/http2/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,13 @@ function mapToHeaders(map,
let count = 0;
const keys = ObjectKeys(map);
const singles = new Set();
let i;
let i, j;
let isArray;
let key;
let value;
let isSingleValueHeader;
let err;
for (i = 0; i < keys.length; i++) {
for (i = 0; i < keys.length; ++i) {
key = keys[i];
value = map[key];
if (value === undefined || key === '')
Expand Down Expand Up @@ -488,8 +488,8 @@ function mapToHeaders(map,
throw new ERR_HTTP2_INVALID_CONNECTION_HEADERS(key);
}
if (isArray) {
for (var k = 0; k < value.length; k++) {
const val = String(value[k]);
for (j = 0; j < value.length; ++j) {
const val = String(value[j]);
ret += `${key}\0${val}\0`;
}
count += value.length;
Expand Down

0 comments on commit e54eb46

Please sign in to comment.