Skip to content

Commit e54eb46

Browse files
mkrawczuktargos
authored andcommittedApr 22, 2020
http2: rename counter in mapToHeaders inner loop
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>
1 parent 776905e commit e54eb46

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎lib/internal/http2/util.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,13 @@ function mapToHeaders(map,
442442
let count = 0;
443443
const keys = ObjectKeys(map);
444444
const singles = new Set();
445-
let i;
445+
let i, j;
446446
let isArray;
447447
let key;
448448
let value;
449449
let isSingleValueHeader;
450450
let err;
451-
for (i = 0; i < keys.length; i++) {
451+
for (i = 0; i < keys.length; ++i) {
452452
key = keys[i];
453453
value = map[key];
454454
if (value === undefined || key === '')
@@ -488,8 +488,8 @@ function mapToHeaders(map,
488488
throw new ERR_HTTP2_INVALID_CONNECTION_HEADERS(key);
489489
}
490490
if (isArray) {
491-
for (var k = 0; k < value.length; k++) {
492-
const val = String(value[k]);
491+
for (j = 0; j < value.length; ++j) {
492+
const val = String(value[j]);
493493
ret += `${key}\0${val}\0`;
494494
}
495495
count += value.length;

0 commit comments

Comments
 (0)
Please sign in to comment.