diff options
author | Brian White <mscdex@mscdex.net> | 2016-12-18 21:25:31 -0500 |
---|---|---|
committer | Brian White <mscdex@mscdex.net> | 2016-12-29 14:19:03 -0500 |
commit | b6ea857c7dabf65c2826c269bb4c8a94fecf40ca (patch) | |
tree | 40c8f75748b3da95c9c21bccc14e714b236027af /lib/_stream_writable.js | |
parent | a54972c195f708afbd985d981b804834817da92b (diff) | |
download | android-node-v8-b6ea857c7dabf65c2826c269bb4c8a94fecf40ca.tar.gz android-node-v8-b6ea857c7dabf65c2826c269bb4c8a94fecf40ca.tar.bz2 android-node-v8-b6ea857c7dabf65c2826c269bb4c8a94fecf40ca.zip |
lib: avoid recompilation of anonymous functions
Since at least V8 5.4, using function.bind() is now fast enough to
use to avoid recompiling/reoptimizing the same anonymous functions.
These changes especially impact http servers.
PR-URL: https://github.com/nodejs/node/pull/6533
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'lib/_stream_writable.js')
-rw-r--r-- | lib/_stream_writable.js | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 06499fc947..b20fe8d2ea 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -86,9 +86,7 @@ function WritableState(options, stream) { this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb) - this.onwrite = function(er) { - onwrite(stream, er); - }; + this.onwrite = onwrite.bind(undefined, stream); // the callback that the user supplies to write(chunk,encoding,cb) this.writecb = null; @@ -538,20 +536,21 @@ function endWritable(stream, state, cb) { function CorkedRequest(state) { this.next = null; this.entry = null; + this.finish = onCorkedFinish.bind(undefined, this, state); +} - this.finish = (err) => { - var entry = this.entry; - this.entry = null; - while (entry) { - var cb = entry.callback; - state.pendingcb--; - cb(err); - entry = entry.next; - } - if (state.corkedRequestsFree) { - state.corkedRequestsFree.next = this; - } else { - state.corkedRequestsFree = this; - } - }; +function onCorkedFinish(corkReq, state, err) { + var entry = corkReq.entry; + corkReq.entry = null; + while (entry) { + var cb = entry.callback; + state.pendingcb--; + cb(err); + entry = entry.next; + } + if (state.corkedRequestsFree) { + state.corkedRequestsFree.next = corkReq; + } else { + state.corkedRequestsFree = corkReq; + } } |