src: don't call v8::Object::SetHiddenValue()
Don't use v8::Object::SetHiddenValue() to keep a reference alive to the buffer, we can just as easily do that from JS land and it's a lot faster to boot. Because the buffer is now a visible property of the write request object, it's essential that we do *not* log it - we'd be effectively serializing the whole buffer to a pretty-printed string.
This commit is contained in:
parent
f548433195
commit
f9b7714b4b
@ -301,7 +301,7 @@ Socket.prototype.send = function(buffer,
|
||||
self.emit('error', ex);
|
||||
}
|
||||
else if (self._handle) {
|
||||
var req = {};
|
||||
var req = { buffer: buffer }; // Keep reference alive.
|
||||
if (callback) {
|
||||
req.callback = callback;
|
||||
req.oncomplete = afterSend;
|
||||
|
10
lib/net.js
10
lib/net.js
@ -640,7 +640,13 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
|
||||
// Retain chunks
|
||||
if (err === 0) req._chunks = chunks;
|
||||
} else {
|
||||
var enc = util.isBuffer(data) ? 'buffer' : encoding;
|
||||
var enc;
|
||||
if (util.isBuffer(data)) {
|
||||
req.buffer = data; // Keep reference alive.
|
||||
enc = 'buffer';
|
||||
} else {
|
||||
enc = encoding;
|
||||
}
|
||||
err = createWriteReq(req, this._handle, data, enc);
|
||||
}
|
||||
|
||||
@ -743,7 +749,7 @@ function afterWrite(status, handle, req) {
|
||||
var self = handle.owner;
|
||||
var state = self._writableState;
|
||||
if (self !== process.stderr && self !== process.stdout)
|
||||
debug('afterWrite', status, req);
|
||||
debug('afterWrite', status);
|
||||
|
||||
// callback may come after call to destroy.
|
||||
if (self.destroyed) {
|
||||
|
@ -49,7 +49,6 @@ using v8::Undefined;
|
||||
using v8::Value;
|
||||
|
||||
|
||||
static Cached<String> buffer_sym;
|
||||
static Cached<String> bytes_sym;
|
||||
static Cached<String> write_queue_size_sym;
|
||||
static Cached<String> onread_sym;
|
||||
@ -63,7 +62,6 @@ void StreamWrap::Initialize(Handle<Object> target) {
|
||||
initialized = true;
|
||||
|
||||
HandleScope scope(node_isolate);
|
||||
buffer_sym = FIXED_ONE_BYTE_STRING(node_isolate, "buffer");
|
||||
bytes_sym = FIXED_ONE_BYTE_STRING(node_isolate, "bytes");
|
||||
write_queue_size_sym = FIXED_ONE_BYTE_STRING(node_isolate, "writeQueueSize");
|
||||
onread_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onread");
|
||||
@ -215,8 +213,6 @@ void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
|
||||
char* storage = new char[sizeof(WriteWrap)];
|
||||
WriteWrap* req_wrap = new(storage) WriteWrap(req_wrap_obj, wrap);
|
||||
|
||||
req_wrap_obj->SetHiddenValue(buffer_sym, buf_obj);
|
||||
|
||||
uv_buf_t buf;
|
||||
WriteBuffer(buf_obj, &buf);
|
||||
|
||||
|
@ -57,7 +57,6 @@ class SendWrap : public ReqWrap<uv_udp_send_t> {
|
||||
|
||||
|
||||
static Persistent<Function> constructor;
|
||||
static Cached<String> buffer_sym;
|
||||
static Cached<String> oncomplete_sym;
|
||||
static Cached<String> onmessage_sym;
|
||||
|
||||
@ -87,7 +86,6 @@ UDPWrap::~UDPWrap() {
|
||||
void UDPWrap::Initialize(Handle<Object> target) {
|
||||
HandleScope scope(node_isolate);
|
||||
|
||||
buffer_sym = FIXED_ONE_BYTE_STRING(node_isolate, "buffer");
|
||||
oncomplete_sym = FIXED_ONE_BYTE_STRING(node_isolate, "oncomplete");
|
||||
onmessage_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onmessage");
|
||||
|
||||
@ -261,7 +259,6 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
|
||||
assert(length <= Buffer::Length(buffer_obj) - offset);
|
||||
|
||||
SendWrap* req_wrap = new SendWrap(req_wrap_obj, have_callback);
|
||||
req_wrap->object()->SetHiddenValue(buffer_sym, buffer_obj);
|
||||
|
||||
uv_buf_t buf = uv_buf_init(Buffer::Data(buffer_obj) + offset,
|
||||
length);
|
||||
|
Loading…
x
Reference in New Issue
Block a user