mirror of https://github.com/nodejs/node.git
buffer: write strings directly from call
Buffer(<String>) used to pass the string to js where it would then be passed back to cpp for processing. Now only the buffer object instantiation is done in js and the string is processed in cpp. Also added a Buffer api that also accepts the encoding.pull/5010/head
parent
bf8dc0762a
commit
f5e13ae9b5
|
@ -113,15 +113,16 @@ size_t Length(Handle<Object> obj) {
|
|||
}
|
||||
|
||||
|
||||
// TODO(trevnorris): would be more efficient to use StringBytes to calculate the
|
||||
// length and write out the data beforehand then do the same as New().
|
||||
Local<Object> New(Handle<String> string) {
|
||||
Local<Object> New(Handle<String> string, enum encoding enc) {
|
||||
HandleScope scope(node_isolate);
|
||||
|
||||
Handle<Value> argv[1] = { string };
|
||||
Local<Object> obj = p_buffer_fn->NewInstance(1, argv);
|
||||
size_t length = StringBytes::Size(string, enc);
|
||||
|
||||
return scope.Close(obj);
|
||||
Local<Object> buf = New(length);
|
||||
char* data = Buffer::Data(buf);
|
||||
StringBytes::Write(data, length, string, enc);
|
||||
|
||||
return scope.Close(buf);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@ NODE_EXTERN size_t Length(v8::Handle<v8::Object> val);
|
|||
// public constructor
|
||||
NODE_EXTERN v8::Local<v8::Object> New(size_t length);
|
||||
// public constructor from string
|
||||
NODE_EXTERN v8::Local<v8::Object> New(v8::Handle<v8::String> string);
|
||||
NODE_EXTERN v8::Local<v8::Object> New(v8::Handle<v8::String> string,
|
||||
enum encoding enc = UTF8);
|
||||
// public constructor - data is copied
|
||||
// TODO(trevnorris): should be something like Copy()
|
||||
NODE_EXTERN v8::Local<v8::Object> New(const char* data, size_t len);
|
||||
|
|
Loading…
Reference in New Issue