http: reduce raw header name allocations

Reuse the values array instead of allocating a second result array.

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
PR-URL: https://github.com/nodejs/node/pull/66488
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Tim Perry <pimterry@gmail.com>
This commit is contained in:
Roberto Bianchi authored and Antoine du Hamel committed 2026-11-11 17:28:08 +01:00
1 parent 63c1bfcc86
commit a64265166c
3 files changed
+79 -5

No files matched your search

+3 -5
View File
@@ -22,7 +22,6 @@
'use strict';
const {
Array,
ArrayIsArray,
MathFloor,
ObjectDefineProperty,
@@ -928,12 +927,11 @@ OutgoingMessage.prototype.getRawHeaderNames = function getRawHeaderNames() {
const headersMap = this[kOutHeaders];
if (headersMap === null) return [];
const values = ObjectValues(headersMap);
const headers = Array(values.length);
const headers = ObjectValues(headersMap);
// Retain for(;;) loop for performance reasons
// Refs: https://github.com/nodejs/node/pull/30958
for (let i = 0, l = values.length; i < l; i++) {
headers[i] = values[i][0];
for (let i = 0; i < headers.length; i++) {
headers[i] = headers[i][0];
}
return headers;