Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
joyeecheung committed Nov 11, 2018
commit 3e3e9b7097e0b51bb0ecc956422119cf6dc6952e
26 changes: 9 additions & 17 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1424,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) {
Comment thread
refack marked this conversation as resolved.
Outdated
auto entry = origin->ov[i];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 auto might make things more readable :)

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/s/nov/origin_v.size()/ for correctness and readability

MakeCallback(env()->onorigin_string(), 1, &holder);
}

Expand Down