diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-08-07 21:50:41 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-08-09 11:44:50 +0200 |
commit | f674b09f40d22915e15b6968aafc5d25ac8178a2 (patch) | |
tree | b227505171dffe126aefde9855b4db2c765e70e1 /src/pipe_wrap.cc | |
parent | c0e70354dbf7dcc76e69dd1973451eb10a2ebdfe (diff) | |
download | android-node-v8-f674b09f40d22915e15b6968aafc5d25ac8178a2.tar.gz android-node-v8-f674b09f40d22915e15b6968aafc5d25ac8178a2.tar.bz2 android-node-v8-f674b09f40d22915e15b6968aafc5d25ac8178a2.zip |
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/pipe_wrap.cc')
-rw-r--r-- | src/pipe_wrap.cc | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 53c8da92dc..1aa90e14c3 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -78,13 +78,13 @@ void PipeWrap::Initialize(Handle<Object> target) { HandleScope scope(node_isolate); Local<FunctionTemplate> t = FunctionTemplate::New(New); - t->SetClassName(String::NewSymbol("Pipe")); + t->SetClassName(FIXED_ONE_BYTE_STRING(node_isolate, "Pipe")); t->InstanceTemplate()->SetInternalFieldCount(1); enum PropertyAttribute attributes = static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete); - t->InstanceTemplate()->SetAccessor(String::New("fd"), + t->InstanceTemplate()->SetAccessor(FIXED_ONE_BYTE_STRING(node_isolate, "fd"), StreamWrap::GetFD, NULL, Handle<Value>(), @@ -117,7 +117,7 @@ void PipeWrap::Initialize(Handle<Object> target) { pipeConstructorTmpl.Reset(node_isolate, t); pipeConstructor.Reset(node_isolate, t->GetFunction()); - target->Set(String::NewSymbol("Pipe"), t->GetFunction()); + target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "Pipe"), t->GetFunction()); } @@ -214,7 +214,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) { // Successful accept. Call the onconnection callback in JavaScript land. argv[1] = client_obj; if (onconnection_sym.IsEmpty()) { - onconnection_sym = String::New("onconnection"); + onconnection_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onconnection"); } MakeCallback(wrap->object(), onconnection_sym, ARRAY_SIZE(argv), argv); } @@ -249,7 +249,7 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) { }; if (oncomplete_sym.IsEmpty()) { - oncomplete_sym = String::New("oncomplete"); + oncomplete_sym = FIXED_ONE_BYTE_STRING(node_isolate, "oncomplete"); } MakeCallback(req_wrap_obj, oncomplete_sym, ARRAY_SIZE(argv), argv); |