diff options
author | isaacs <i@izs.me> | 2013-03-03 19:14:06 -0800 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-03-05 14:27:15 -0800 |
commit | 426b4c625802c7b6913fa09237aa9745bf3ae84a (patch) | |
tree | 81756bcb6720145decb01160df08b5315784657b /lib/net.js | |
parent | cd68d86c3283af2f4b3c349c2081c609e3978b9b (diff) | |
download | android-node-v8-426b4c625802c7b6913fa09237aa9745bf3ae84a.tar.gz android-node-v8-426b4c625802c7b6913fa09237aa9745bf3ae84a.tar.bz2 android-node-v8-426b4c625802c7b6913fa09237aa9745bf3ae84a.zip |
stream: _write takes an encoding argument
This vastly reduces the overhead of decodeStrings:false streams,
such as net and http.
Diffstat (limited to 'lib/net.js')
-rw-r--r-- | lib/net.js | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/net.js b/lib/net.js index 35223c3396..4821665218 100644 --- a/lib/net.js +++ b/lib/net.js @@ -161,7 +161,8 @@ function Socket(options) { initSocketHandle(this); - this._pendingWrite = null; + this._pendingData = null; + this._pendingEncoding = ''; // handle strings directly this._writableState.decodeStrings = false; @@ -583,22 +584,20 @@ Socket.prototype.write = function(chunk, encoding, cb) { }; -Socket.prototype._write = function(dataEncoding, cb) { - // assert(Array.isArray(dataEncoding)); - var data = dataEncoding[0]; - var encoding = dataEncoding[1] || 'utf8'; - +Socket.prototype._write = function(data, encoding, cb) { // If we are still connecting, then buffer this for later. // The Writable logic will buffer up any more writes while // waiting for this one to be done. if (this._connecting) { - this._pendingWrite = dataEncoding; + this._pendingData = data; + this._pendingEncoding = encoding; this.once('connect', function() { - this._write(dataEncoding, cb); + this._write(data, encoding, cb); }); return; } - this._pendingWrite = null; + this._pendingData = null; + this._pendingEncoding = ''; timers.active(this); @@ -651,15 +650,16 @@ function createWriteReq(handle, data, encoding) { Socket.prototype.__defineGetter__('bytesWritten', function() { var bytes = this._bytesDispatched, state = this._writableState, - pending = this._pendingWrite; + data = this._pendingData, + encoding = this._pendingEncoding; state.buffer.forEach(function(el) { el = el[0]; bytes += Buffer.byteLength(el[0], el[1]); }); - if (pending) - bytes += Buffer.byteLength(pending[0], pending[1]); + if (data) + bytes += Buffer.byteLength(data, encoding); return bytes; }); |