@@ -16,13 +16,6 @@ util.inherits(Writable, Stream);
1616
1717function nop ( ) { }
1818
19- function WriteReq ( chunk , encoding , cb ) {
20- this . chunk = chunk ;
21- this . encoding = encoding ;
22- this . callback = cb ;
23- this . next = null ;
24- }
25-
2619function WritableState ( options , stream ) {
2720 options = options || { } ;
2821
@@ -113,7 +106,9 @@ function WritableState(options, stream) {
113106
114107 // allocate the first CorkedRequest, there is always
115108 // one allocated and free to use, and we maintain at most two
116- this . corkedRequestsFree = new CorkedRequest ( this ) ;
109+ var corkReq = { next : null , entry : null , finish : undefined } ;
110+ corkReq . finish = onCorkedFinish . bind ( undefined , corkReq , this ) ;
111+ this . corkedRequestsFree = corkReq ;
117112}
118113
119114WritableState . prototype . getBuffer = function getBuffer ( ) {
@@ -304,7 +299,7 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
304299
305300 if ( state . writing || state . corked ) {
306301 var last = state . lastBufferedRequest ;
307- state . lastBufferedRequest = new WriteReq ( chunk , encoding , cb ) ;
302+ state . lastBufferedRequest = { chunk, encoding, callback : cb , next : null } ;
308303 if ( last ) {
309304 last . next = state . lastBufferedRequest ;
310305 } else {
@@ -423,7 +418,9 @@ function clearBuffer(stream, state) {
423418 state . corkedRequestsFree = holder . next ;
424419 holder . next = null ;
425420 } else {
426- state . corkedRequestsFree = new CorkedRequest ( state ) ;
421+ var corkReq = { next : null , entry : null , finish : undefined } ;
422+ corkReq . finish = onCorkedFinish . bind ( undefined , corkReq , state ) ;
423+ state . corkedRequestsFree = corkReq ;
427424 }
428425 } else {
429426 // Slow case, write chunks one-by-one
@@ -528,14 +525,6 @@ function endWritable(stream, state, cb) {
528525 stream . writable = false ;
529526}
530527
531- // It seems a linked list but it is not
532- // there will be only 2 of these for each stream
533- function CorkedRequest ( state ) {
534- this . next = null ;
535- this . entry = null ;
536- this . finish = onCorkedFinish . bind ( undefined , this , state ) ;
537- }
538-
539528function onCorkedFinish ( corkReq , state , err ) {
540529 var entry = corkReq . entry ;
541530 corkReq . entry = null ;
0 commit comments