summaryrefslogtreecommitdiff
path: root/src/node_stat_watcher.cc
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-08-07 21:50:41 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-08-09 11:44:50 +0200
commitf674b09f40d22915e15b6968aafc5d25ac8178a2 (patch)
treeb227505171dffe126aefde9855b4db2c765e70e1 /src/node_stat_watcher.cc
parentc0e70354dbf7dcc76e69dd1973451eb10a2ebdfe (diff)
downloadnode-new-f674b09f40d22915e15b6968aafc5d25ac8178a2.tar.gz
src: use v8::String::NewFrom*() functions
* Change calls to String::New() and String::NewSymbol() to their respective one-byte, two-byte and UTF-8 counterparts. * Add a FIXED_ONE_BYTE_STRING macro that takes a string literal and turns it into a v8::Local<v8::String>. * Add helper functions that make v8::String::NewFromOneByte() easier to work with. Said function expects a `const uint8_t*` but almost every call site deals with `const char*` or `const unsigned char*`. Helps us avoid doing reinterpret_casts all over the place. * Code that handles file system paths keeps using UTF-8 for backwards compatibility reasons. At least now the use of UTF-8 is explicit. * Remove v8::String::NewSymbol() entirely. Almost all call sites were effectively minor de-optimizations. If you create a string only once, there is no point in making it a symbol. If you are create the same string repeatedly, it should probably be cached in a persistent handle.
Diffstat (limited to 'src/node_stat_watcher.cc')
-rw-r--r--src/node_stat_watcher.cc9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc
index 96e8c192a6..fb3cf4f8aa 100644
--- a/src/node_stat_watcher.cc
+++ b/src/node_stat_watcher.cc
@@ -46,12 +46,13 @@ void StatWatcher::Initialize(Handle<Object> target) {
Local<FunctionTemplate> t = FunctionTemplate::New(StatWatcher::New);
t->InstanceTemplate()->SetInternalFieldCount(1);
- t->SetClassName(String::NewSymbol("StatWatcher"));
+ t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "StatWatcher"));
NODE_SET_PROTOTYPE_METHOD(t, "start", StatWatcher::Start);
NODE_SET_PROTOTYPE_METHOD(t, "stop", StatWatcher::Stop);
- target->Set(String::NewSymbol("StatWatcher"), t->GetFunction());
+ target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "StatWatcher"),
+ t->GetFunction());
}
@@ -85,7 +86,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
argv[1] = BuildStatsObject(prev);
argv[2] = Integer::New(status, node_isolate);
if (onchange_sym.IsEmpty()) {
- onchange_sym = String::New("onchange");
+ onchange_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onchange");
}
MakeCallback(wrap->handle(node_isolate),
onchange_sym,
@@ -121,7 +122,7 @@ void StatWatcher::Stop(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(node_isolate);
StatWatcher* wrap = ObjectWrap::Unwrap<StatWatcher>(args.This());
if (onstop_sym.IsEmpty()) {
- onstop_sym = String::New("onstop");
+ onstop_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onstop");
}
MakeCallback(wrap->handle(node_isolate), onstop_sym, 0, NULL);
wrap->Stop();