net: Don't go through Stream API when ondata is used
authorisaacs <i@izs.me>
Thu, 27 Dec 2012 21:03:59 +0000 (13:03 -0800)
committerisaacs <i@izs.me>
Sat, 29 Dec 2012 23:32:25 +0000 (15:32 -0800)
This speeds up http_simple by around 6%.

lib/net.js

index 4a5fbe5..fc56918 100644 (file)
@@ -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');