-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
src: remove pushValueToArray and setupProcessObject #24264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
a9f8f33
3e3e9b7
fa1c240
a96a222
d79ed5d
70fa3c1
a54d0c6
db5e5fa
0b3568c
a44e978
fcaf05a
07b5417
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1292,45 +1292,30 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) { | |
| Local<String> value_str; | ||
|
|
||
| Local<Array> holder = Array::New(isolate); | ||
| Local<Function> fn = env()->push_values_to_array_function(); | ||
| Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX * 2]; | ||
|
|
||
| // The headers are passed in above as a queue of nghttp2_header structs. | ||
| // The following converts that into a JS array with the structure: | ||
| // [name1, value1, name2, value2, name3, value3, name3, value4] and so on. | ||
| // That array is passed up to the JS layer and converted into an Object form | ||
| // like {name1: value1, name2: value2, name3: [value3, value4]}. We do it | ||
| // this way for performance reasons (it's faster to generate and pass an | ||
| // array than it is to generate and pass the object). | ||
| size_t n = 0; | ||
| while (n < headers.size()) { | ||
| size_t j = 0; | ||
| while (n < headers.size() && j < arraysize(argv) / 2) { | ||
| nghttp2_header item = headers[n++]; | ||
| // The header name and value are passed as external one-byte strings | ||
| name_str = | ||
| ExternalHeader::New<true>(this, item.name).ToLocalChecked(); | ||
| value_str = | ||
| ExternalHeader::New<false>(this, item.value).ToLocalChecked(); | ||
| argv[j * 2] = name_str; | ||
| argv[j * 2 + 1] = value_str; | ||
| j++; | ||
| } | ||
| // For performance, we pass name and value pairs to array.protototype.push | ||
| // in batches of size NODE_PUSH_VAL_TO_ARRAY_MAX * 2 until there are no | ||
| // more items to push. | ||
| if (j > 0) { | ||
| fn->Call(env()->context(), holder, j * 2, argv).ToLocalChecked(); | ||
| } | ||
| size_t headers_size = headers.size(); | ||
| std::vector<Local<Value>> headers_v(headers_size * 2); | ||
| for (size_t i = 0; i < headers_size; ++i) { | ||
|
refack marked this conversation as resolved.
Outdated
|
||
| nghttp2_header item = headers[i]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW: this is an unneeded copy
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! (though I realize it's originally that way :/)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the compiler should be able optimize this away anyway? |
||
| // The header name and value are passed as external one-byte strings | ||
| headers_v[i * 2] = | ||
| ExternalHeader::New<true>(this, item.name).ToLocalChecked(); | ||
| headers_v[i * 2 + 1] = | ||
| ExternalHeader::New<false>(this, item.value).ToLocalChecked(); | ||
| } | ||
|
|
||
| Local<Value> args[5] = { | ||
|
refack marked this conversation as resolved.
Outdated
|
||
| stream->object(), | ||
| Integer::New(isolate, id), | ||
| Integer::New(isolate, stream->headers_category()), | ||
| Integer::New(isolate, frame->hd.flags), | ||
| holder | ||
| }; | ||
| stream->object(), | ||
| Integer::New(isolate, id), | ||
| Integer::New(isolate, stream->headers_category()), | ||
| Integer::New(isolate, frame->hd.flags), | ||
| Array::New(isolate, headers_v.data(), headers_size * 2)}; | ||
| MakeCallback(env()->onheaders_string(), arraysize(args), args); | ||
| } | ||
|
|
||
|
|
@@ -1439,25 +1424,17 @@ void Http2Session::HandleOriginFrame(const nghttp2_frame* frame) { | |
| nghttp2_extension ext = frame->ext; | ||
| nghttp2_ext_origin* origin = static_cast<nghttp2_ext_origin*>(ext.payload); | ||
|
|
||
| Local<Value> holder = Array::New(isolate); | ||
| Local<Function> fn = env()->push_values_to_array_function(); | ||
| Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX]; | ||
| size_t nov = origin->nov; | ||
| std::vector<Local<Value>> origin_v(nov); | ||
|
|
||
| size_t n = 0; | ||
| while (n < origin->nov) { | ||
| size_t j = 0; | ||
| while (n < origin->nov && j < arraysize(argv)) { | ||
| auto entry = origin->ov[n++]; | ||
| argv[j++] = | ||
| String::NewFromOneByte(isolate, | ||
| entry.origin, | ||
| v8::NewStringType::kNormal, | ||
| entry.origin_len).ToLocalChecked(); | ||
| } | ||
| if (j > 0) | ||
| fn->Call(context, holder, j, argv).ToLocalChecked(); | ||
| for (size_t i = 0; i < nov; ++i) { | ||
|
refack marked this conversation as resolved.
Outdated
|
||
| auto entry = origin->ov[i]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is copy-pasted, but I think getting rid of this |
||
| origin_v[i] = | ||
| String::NewFromOneByte( | ||
| isolate, entry.origin, v8::NewStringType::kNormal, entry.origin_len) | ||
| .ToLocalChecked(); | ||
| } | ||
|
|
||
| Local<Value> holder = Array::New(isolate, origin_v.data(), nov); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| MakeCallback(env()->onorigin_string(), 1, &holder); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.