Permalink
Browse files

stream: use plain objects for write/corked reqs

This is similar to a change made awhile back for storing
process.nextTick() requests.

PR-URL: #10558
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
  • Loading branch information...
mscdex committed Dec 31, 2016
1 parent b888bfe commit a3539ae3be51c54f0b2f1619e18980fc1a2cb8d2
Showing with 7 additions and 18 deletions.
  1. +7 −18 lib/_stream_writable.js
View
@@ -16,13 +16,6 @@ util.inherits(Writable, Stream);
function nop() {}
function WriteReq(chunk, encoding, cb) {
this.chunk = chunk;
this.encoding = encoding;
this.callback = cb;
this.next = null;
}
function WritableState(options, stream) {
options = options || {};
@@ -113,7 +106,9 @@ function WritableState(options, stream) {
// allocate the first CorkedRequest, there is always
// one allocated and free to use, and we maintain at most two
this.corkedRequestsFree = new CorkedRequest(this);
var corkReq = { next: null, entry: null, finish: undefined };
corkReq.finish = onCorkedFinish.bind(undefined, corkReq, this);
this.corkedRequestsFree = corkReq;
}
WritableState.prototype.getBuffer = function getBuffer() {
@@ -304,7 +299,7 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
if (state.writing || state.corked) {
var last = state.lastBufferedRequest;
state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
state.lastBufferedRequest = { chunk, encoding, callback: cb, next: null };
if (last) {
last.next = state.lastBufferedRequest;
} else {
@@ -423,7 +418,9 @@ function clearBuffer(stream, state) {
state.corkedRequestsFree = holder.next;
holder.next = null;
} else {
state.corkedRequestsFree = new CorkedRequest(state);
var corkReq = { next: null, entry: null, finish: undefined };
corkReq.finish = onCorkedFinish.bind(undefined, corkReq, state);
state.corkedRequestsFree = corkReq;
}
} else {
// Slow case, write chunks one-by-one
@@ -528,14 +525,6 @@ function endWritable(stream, state, cb) {
stream.writable = false;
}
// It seems a linked list but it is not
// there will be only 2 of these for each stream
function CorkedRequest(state) {
this.next = null;
this.entry = null;
this.finish = onCorkedFinish.bind(undefined, this, state);
}
function onCorkedFinish(corkReq, state, err) {
var entry = corkReq.entry;
corkReq.entry = null;

0 comments on commit a3539ae

Please sign in to comment.