@@ -16,13 +16,6 @@ util.inherits(Writable, Stream);
16
16
17
17
function nop ( ) { }
18
18
19
- function WriteReq ( chunk , encoding , cb ) {
20
- this . chunk = chunk ;
21
- this . encoding = encoding ;
22
- this . callback = cb ;
23
- this . next = null ;
24
- }
25
-
26
19
function WritableState ( options , stream ) {
27
20
options = options || { } ;
28
21
@@ -113,7 +106,9 @@ function WritableState(options, stream) {
113
106
114
107
// allocate the first CorkedRequest, there is always
115
108
// 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 ;
117
112
}
118
113
119
114
WritableState . prototype . getBuffer = function getBuffer ( ) {
@@ -304,7 +299,7 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
304
299
305
300
if ( state . writing || state . corked ) {
306
301
var last = state . lastBufferedRequest ;
307
- state . lastBufferedRequest = new WriteReq ( chunk , encoding , cb ) ;
302
+ state . lastBufferedRequest = { chunk, encoding, callback : cb , next : null } ;
308
303
if ( last ) {
309
304
last . next = state . lastBufferedRequest ;
310
305
} else {
@@ -423,7 +418,9 @@ function clearBuffer(stream, state) {
423
418
state . corkedRequestsFree = holder . next ;
424
419
holder . next = null ;
425
420
} 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 ;
427
424
}
428
425
} else {
429
426
// Slow case, write chunks one-by-one
@@ -528,14 +525,6 @@ function endWritable(stream, state, cb) {
528
525
stream . writable = false ;
529
526
}
530
527
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
-
539
528
function onCorkedFinish ( corkReq , state , err ) {
540
529
var entry = corkReq . entry ;
541
530
corkReq . entry = null ;
0 commit comments