Browse Source

net: Don't go through Stream API when ondata is used

This speeds up http_simple by around 6%.
v0.9.5-release
isaacs 12 years ago
parent
commit
e11668b244
  1. 8
      lib/net.js

8
lib/net.js

@ -461,7 +461,10 @@ function onread(buffer, offset, length) {
// if it's not enough data, we'll just call handle.readStart() // if it's not enough data, we'll just call handle.readStart()
// again right away. // again right away.
self.bytesRead += length; self.bytesRead += length;
self._readableState.onread(null, buffer.slice(offset, end));
// Optimization: emit the original buffer with end points
if (self.ondata) self.ondata(buffer, offset, end);
else self._readableState.onread(null, buffer.slice(offset, end));
if (handle.reading && !self._readableState.reading) { if (handle.reading && !self._readableState.reading) {
handle.reading = false; handle.reading = false;
@ -471,9 +474,6 @@ function onread(buffer, offset, length) {
self._destroy(errnoException(errno, 'read')); self._destroy(errnoException(errno, 'read'));
} }
// Optimization: emit the original buffer with end points
if (self.ondata) self.ondata(buffer, offset, end);
} else if (errno == 'EOF') { } else if (errno == 'EOF') {
debug('EOF'); debug('EOF');

Loading…
Cancel
Save