Browse Source

stream: use plain objects for write/corked reqs

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

PR-URL: https://github.com/nodejs/node/pull/10558
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
v6
Brian White 8 years ago
parent
commit
a3539ae3be
No known key found for this signature in database GPG Key ID: 606D7358F94DA209
  1. 25
      lib/_stream_writable.js

25
lib/_stream_writable.js

@ -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;

Loading…
Cancel
Save