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/node_buffer.cc | |
parent | c0e70354dbf7dcc76e69dd1973451eb10a2ebdfe (diff) | |
download | node-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_buffer.cc')
-rw-r--r-- | src/node_buffer.cc | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 480b2757e6..b69ff63bf2 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -559,13 +559,14 @@ void SetupBufferJS(const FunctionCallbackInfo<Value>& args) { Local<Function> bv = args[0].As<Function>(); p_buffer_fn.Reset(node_isolate, bv); - Local<Value> proto_v = bv->Get(String::New("prototype")); + Local<Value> proto_v = + bv->Get(FIXED_ONE_BYTE_STRING(node_isolate, "prototype")); assert(proto_v->IsObject()); Local<Object> proto = proto_v.As<Object>(); - bv->Set(String::New("byteLength"), + bv->Set(FIXED_ONE_BYTE_STRING(node_isolate, "byteLength"), FunctionTemplate::New(ByteLength)->GetFunction()); NODE_SET_METHOD(proto, "asciiSlice", AsciiSlice); @@ -596,14 +597,16 @@ void SetupBufferJS(const FunctionCallbackInfo<Value>& args) { NODE_SET_METHOD(proto, "fill", Fill); // for backwards compatibility - proto->Set(String::New("offset"), Uint32::New(0, node_isolate), v8::ReadOnly); + proto->Set(FIXED_ONE_BYTE_STRING(node_isolate, "offset"), + Uint32::New(0, node_isolate), + v8::ReadOnly); } void Initialize(Handle<Object> target) { HandleScope scope(node_isolate); - target->Set(String::New("setupBufferJS"), + target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "setupBufferJS"), FunctionTemplate::New(SetupBufferJS)->GetFunction()); } |