Skip to content

Commit 301b44d

Browse files
committed
Chunk strings together on Stream buffer
1 parent c75e4cb commit 301b44d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/net.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,15 @@ Stream.prototype.write = function (data, encoding) {
504504
if (this._writeQueueLast() === END_OF_FILE) {
505505
throw new Error('Stream.close() called already; cannot write.');
506506
}
507-
this._writeQueue.push(data); // TODO if string of the same encoding concat?
508-
this._writeQueueEncoding.push(encoding);
507+
508+
if (typeof data == 'string' &&
509+
this._writeQueueEncoding[this._writeQueueEncoding.length-1] === encoding) {
510+
// optimization - concat onto last
511+
this._writeQueue[this._writeQueue.length-1] += data;
512+
} else {
513+
this._writeQueue.push(data);
514+
this._writeQueueEncoding.push(encoding);
515+
}
509516
return false;
510517
} else {
511518
// Fast.

test/disabled/test-http-big-proxy-responses.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var chargen = http.createServer(function (req, res) {
1212
assert.ok(len > 0);
1313
res.writeHead(200, {"transfer-encoding":"chunked"});
1414
for (var i=0; i<len; i++) {
15-
//print(',');
15+
if (i % 1000 == 0) print(',');
1616
res.write(chunk);
1717
}
1818
res.end();
@@ -38,8 +38,10 @@ var proxy = http.createServer(function (req, res) {
3838
proxy_req.addListener('response', function(proxy_res) {
3939
res.writeHead(proxy_res.statusCode, proxy_res.headers);
4040

41+
var count = 0;
42+
4143
proxy_res.addListener('data', function(d) {
42-
//print('.');
44+
if (count++ % 1000 == 0) print('.');
4345
res.write(d);
4446
sent += d.length;
4547
assert.ok(sent <= (len*chunk.length));

0 commit comments

Comments
 (0)