Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

wip: prevent some deopts in net-pipe

  • Loading branch information...
commit 468929e1592fe92ed3b77241fbb60e9b418275d9 1 parent d8c9f12
@isaacs authored
Showing with 14 additions and 25 deletions.
  1. +14 −25 lib/_stream_readable.js
View
39 lib/_stream_readable.js
@@ -136,7 +136,7 @@ function howMuchToRead(n, state) {
if (state.objectMode)
return n === 0 ? 0 : 1;
- if (isNaN(n) || n === null)
+ if (n === undefined || n === null)
return state.length;
if (n <= 0)
@@ -191,19 +191,14 @@ function callAsyncRead(self, state) {
state.sync = false;
}
+// If _read called its callback synchronously, then `reading`
+// will be false, and we need to re-evaluate how much data we
+// can return to the user.
function afterAsyncRead(self, state, n, nOrig, doRead) {
-
- // If _read called its callback synchronously, then `reading`
- // will be false, and we need to re-evaluate how much data we
- // can return to the user.
if (doRead && !state.reading)
n = howMuchToRead(nOrig, state);
- var ret;
- if (n > 0)
- ret = fromList(n, state);
- else
- ret = null;
+ var ret = (n > 0) ? fromList(n, state) : null;
if (ret === null || (!state.objectMode && ret.length === 0)) {
state.needReadable = true;
@@ -212,15 +207,10 @@ function afterAsyncRead(self, state, n, nOrig, doRead) {
state.length -= n;
- // If we have nothing in the buffer, then we want to know
- // as soon as we *do* get something into the buffer.
if (state.length === 0 && !state.ended)
state.needReadable = true;
- // If we happened to read() exactly the remaining amount in the
- // buffer, and the EOF has been seen at this point, then make sure
- // that we emit 'end' on the very next tick.
- if (state.ended && !state.endEmitted && state.length === 0)
+ if (state.ended && state.length === 0)
endReadable(self);
return ret;
@@ -409,7 +399,9 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
// on the source. This would be more elegant with a .once()
// handler in flow(), but adding and removing repeatedly is
// too slow.
- var ondrain = pipeOnDrain(src);
+ function ondrain() {
+ pipeOnDrain(src, dest);
+ }
dest.on('drain', ondrain);
function cleanup() {
@@ -472,14 +464,11 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
return dest;
};
-function pipeOnDrain(src) {
- return function() {
- var dest = this;
- var state = src._readableState;
- state.awaitDrain--;
- if (state.awaitDrain === 0)
- flow(src);
- };
+function pipeOnDrain(src, dest) {
+ var state = src._readableState;
+ state.awaitDrain--;
+ if (state.awaitDrain === 0)
+ flow(src);
}
function flow(src) {
Please sign in to comment.
Something went wrong with that request. Please try again.