Skip to content
Closed
Show file tree
Hide file tree
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
src: use kInternalized instead of kNormal
Use v8::NewStringType::kInternalized instead of
v8::NewStringType::kNormal in different calls to v8::String::NewFromUtf8
in node.h and node.cc wherever it makes sense, to save the GC some work
which would largely be redundant.
  • Loading branch information
ryzokuken committed Jul 21, 2018
commit 560e336e82006f3aa6e69ef9997bf80cedeeb4c4
4 changes: 2 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2352,11 +2352,11 @@ void SetupProcessObject(Environment* env,
if (uv_exepath(exec_path, &exec_path_len) == 0) {
exec_path_value = String::NewFromUtf8(env->isolate(),
exec_path,
v8::NewStringType::kNormal,
v8::NewStringType::kInternalized,
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.

Here on the other hand I don't know why this needs to be internalized.

exec_path_len).ToLocalChecked();
} else {
exec_path_value = String::NewFromUtf8(env->isolate(), argv[0],
v8::NewStringType::kNormal).ToLocalChecked();
v8::NewStringType::kInternalized).ToLocalChecked();
}
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
exec_path_value);
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.

Since we expect process.execPath to be long-lived, using internalized strings might make more sense. (It probably doesn’t matter all that much in individual cases like these, but the sum of the work we’re saving the GC might matter a bit.)

Expand Down
8 changes: 4 additions & 4 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ NODE_EXTERN struct uv_loop_s* GetCurrentEventLoop(v8::Isolate* isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext(); \
v8::Local<v8::String> constant_name = \
v8::String::NewFromUtf8(isolate, #constant, \
v8::NewStringType::kNormal).ToLocalChecked(); \
v8::NewStringType::kInternalized).ToLocalChecked(); \
v8::Local<v8::Number> constant_value = \
v8::Number::New(isolate, static_cast<double>(constant)); \
v8::PropertyAttribute constant_attributes = \
Expand Down Expand Up @@ -346,7 +346,7 @@ inline void NODE_SET_METHOD(v8::Local<v8::Template> recv,
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
callback);
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
v8::NewStringType::kNormal).ToLocalChecked();
v8::NewStringType::kInternalized).ToLocalChecked();
t->SetClassName(fn_name);
recv->Set(fn_name, t);
}
Expand All @@ -361,7 +361,7 @@ inline void NODE_SET_METHOD(v8::Local<v8::Object> recv,
callback);
v8::Local<v8::Function> fn = t->GetFunction();
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
v8::NewStringType::kNormal).ToLocalChecked();
v8::NewStringType::kInternalized).ToLocalChecked();
fn->SetName(fn_name);
recv->Set(fn_name, fn);
}
Expand All @@ -378,7 +378,7 @@ inline void NODE_SET_PROTOTYPE_METHOD(v8::Local<v8::FunctionTemplate> recv,
v8::Local<v8::FunctionTemplate> t =
v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), s);
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
v8::NewStringType::kNormal).ToLocalChecked();
v8::NewStringType::kInternalized).ToLocalChecked();
t->SetClassName(fn_name);
recv->PrototypeTemplate()->Set(fn_name, t);
}
Expand Down