From 301b44d45da94b2f5ab175769fe655270a4cca92 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 29 Apr 2010 11:57:52 -0700 Subject: [PATCH] Chunk strings together on Stream buffer --- lib/net.js | 11 +++++++++-- test/disabled/test-http-big-proxy-responses.js | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/net.js b/lib/net.js index 04ca00f..74659cc 100644 --- a/lib/net.js +++ b/lib/net.js @@ -504,8 +504,15 @@ Stream.prototype.write = function (data, encoding) { if (this._writeQueueLast() === END_OF_FILE) { throw new Error('Stream.close() called already; cannot write.'); } - this._writeQueue.push(data); // TODO if string of the same encoding concat? - this._writeQueueEncoding.push(encoding); + + if (typeof data == 'string' && + this._writeQueueEncoding[this._writeQueueEncoding.length-1] === encoding) { + // optimization - concat onto last + this._writeQueue[this._writeQueue.length-1] += data; + } else { + this._writeQueue.push(data); + this._writeQueueEncoding.push(encoding); + } return false; } else { // Fast. diff --git a/test/disabled/test-http-big-proxy-responses.js b/test/disabled/test-http-big-proxy-responses.js index a75ff87..9ddb966 100644 --- a/test/disabled/test-http-big-proxy-responses.js +++ b/test/disabled/test-http-big-proxy-responses.js @@ -12,7 +12,7 @@ var chargen = http.createServer(function (req, res) { assert.ok(len > 0); res.writeHead(200, {"transfer-encoding":"chunked"}); for (var i=0; i