From e11668b244ee62d9997d4871f368075b8abf8d45 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 27 Dec 2012 13:03:59 -0800 Subject: [PATCH] net: Don't go through Stream API when ondata is used This speeds up http_simple by around 6%. --- lib/net.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/net.js b/lib/net.js index 4a5fbe56e0..fc56918eba 100644 --- a/lib/net.js +++ b/lib/net.js @@ -461,7 +461,10 @@ function onread(buffer, offset, length) { // if it's not enough data, we'll just call handle.readStart() // again right away. 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) { handle.reading = false; @@ -471,9 +474,6 @@ function onread(buffer, offset, length) { 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') { debug('EOF');