Skip to content
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

src: internalize per-isolate string properties #3060

Merged
merged 2 commits into from
Sep 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 27 additions & 4 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,26 @@ inline void Environment::IsolateData::Put() {
}
}

// Create string properties as internalized one byte strings.
//
// Internalized because it makes property lookups a little faster and because
// the string is created in the old space straight away. It's going to end up
// in the old space sooner or later anyway but now it doesn't go through
// v8::Eternal's new space handling first.
//
// One byte because our strings are ASCII and we can safely skip V8's UTF-8
// decoding step. It's a one-time cost, but why pay it when you don't have to?
inline Environment::IsolateData::IsolateData(v8::Isolate* isolate,
uv_loop_t* loop)
: event_loop_(loop),
isolate_(isolate),
#define V(PropertyName, StringValue) \
PropertyName ## _(isolate, FIXED_ONE_BYTE_STRING(isolate, StringValue)),
PropertyName ## _(isolate, \
v8::String::NewFromOneByte( \
isolate, \
reinterpret_cast<const uint8_t*>(StringValue), \
v8::NewStringType::kInternalized, \
sizeof(StringValue) - 1).ToLocalChecked()),
PER_ISOLATE_STRING_PROPERTIES(V)
#undef V
ref_count_(0) {}
Expand Down Expand Up @@ -464,7 +478,10 @@ inline void Environment::SetMethod(v8::Local<v8::Object> that,
v8::FunctionCallback callback) {
v8::Local<v8::Function> function =
NewFunctionTemplate(callback)->GetFunction();
v8::Local<v8::String> name_string = v8::String::NewFromUtf8(isolate(), name);
// kInternalized strings are created in the old space.
const v8::NewStringType type = v8::NewStringType::kInternalized;
v8::Local<v8::String> name_string =
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
that->Set(name_string, function);
function->SetName(name_string); // NODE_SET_METHOD() compatibility.
}
Expand All @@ -475,7 +492,10 @@ inline void Environment::SetProtoMethod(v8::Local<v8::FunctionTemplate> that,
v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that);
v8::Local<v8::Function> function =
NewFunctionTemplate(callback, signature)->GetFunction();
v8::Local<v8::String> name_string = v8::String::NewFromUtf8(isolate(), name);
// kInternalized strings are created in the old space.
const v8::NewStringType type = v8::NewStringType::kInternalized;
v8::Local<v8::String> name_string =
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
that->PrototypeTemplate()->Set(name_string, function);
function->SetName(name_string); // NODE_SET_PROTOTYPE_METHOD() compatibility.
}
Expand All @@ -485,7 +505,10 @@ inline void Environment::SetTemplateMethod(v8::Local<v8::FunctionTemplate> that,
v8::FunctionCallback callback) {
v8::Local<v8::Function> function =
NewFunctionTemplate(callback)->GetFunction();
v8::Local<v8::String> name_string = v8::String::NewFromUtf8(isolate(), name);
// kInternalized strings are created in the old space.
const v8::NewStringType type = v8::NewStringType::kInternalized;
v8::Local<v8::String> name_string =
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
that->Set(name_string, function);
function->SetName(name_string); // NODE_SET_METHOD() compatibility.
}
Expand Down
2 changes: 1 addition & 1 deletion src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace node {
#endif

// Strings are per-isolate primitives but Environment proxies them
// for the sake of convenience.
// for the sake of convenience. Strings should be ASCII-only.
#define PER_ISOLATE_STRING_PROPERTIES(V) \
V(address_string, "address") \
V(args_string, "args") \
Expand Down