Skip to content

Commit 62fefd8

Browse files
joyeecheungBridgeAR
authored andcommitted
http2: remove pushValueToArray in Http2Session::HandleOriginFrame
Instead of calling into JS from C++ to push values into an array, use the new Array::New API that takes a pointer and a length directly. PR-URL: #24264 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 7ffbb1f commit 62fefd8

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/node_http2.cc

+9-17
Original file line numberDiff line numberDiff line change
@@ -1424,25 +1424,17 @@ void Http2Session::HandleOriginFrame(const nghttp2_frame* frame) {
14241424
nghttp2_extension ext = frame->ext;
14251425
nghttp2_ext_origin* origin = static_cast<nghttp2_ext_origin*>(ext.payload);
14261426

1427-
Local<Value> holder = Array::New(isolate);
1428-
Local<Function> fn = env()->push_values_to_array_function();
1429-
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX];
1427+
size_t nov = origin->nov;
1428+
std::vector<Local<Value>> origin_v(nov);
14301429

1431-
size_t n = 0;
1432-
while (n < origin->nov) {
1433-
size_t j = 0;
1434-
while (n < origin->nov && j < arraysize(argv)) {
1435-
auto entry = origin->ov[n++];
1436-
argv[j++] =
1437-
String::NewFromOneByte(isolate,
1438-
entry.origin,
1439-
v8::NewStringType::kNormal,
1440-
entry.origin_len).ToLocalChecked();
1441-
}
1442-
if (j > 0)
1443-
fn->Call(context, holder, j, argv).ToLocalChecked();
1430+
for (size_t i = 0; i < nov; ++i) {
1431+
const nghttp2_origin_entry& entry = origin->ov[i];
1432+
origin_v[i] =
1433+
String::NewFromOneByte(
1434+
isolate, entry.origin, v8::NewStringType::kNormal, entry.origin_len)
1435+
.ToLocalChecked();
14441436
}
1445-
1437+
Local<Value> holder = Array::New(isolate, origin_v.data(), origin_v.size());
14461438
MakeCallback(env()->onorigin_string(), 1, &holder);
14471439
}
14481440

0 commit comments

Comments
 (0)