Skip to content

Commit

Permalink
http: don't slice unless necessary
Browse files Browse the repository at this point in the history
The incoming Buffer was being sliced just to possibly not be used.
Instead place the .slice inside the conditional to not be created unless
necessary.
  • Loading branch information
trevnorris committed May 15, 2013
1 parent f0d80d7 commit 88333f7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,10 @@ function connectionListener(socket) {
parser.finish();
freeParser(parser, req);

// This is start + byteParsed
var bodyHead = d.slice(start + bytesParsed, end);

var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
if (EventEmitter.listenerCount(self, eventName) > 0) {
// This is start + byteParsed
var bodyHead = d.slice(start + bytesParsed, end);
self.emit(eventName, req, req.socket, bodyHead);
} else {
// Got upgrade header or CONNECT method, but have no handler.
Expand Down

0 comments on commit 88333f7

Please sign in to comment.