@@ -19,7 +19,6 @@ use arc::{Arc,RWArc};
19
19
use treemap:: TreeMap ;
20
20
use std:: cell:: Cell ;
21
21
use std:: comm:: { PortOne , oneshot} ;
22
- use std:: either:: { Either , Left , Right } ;
23
22
use std:: { io, os, task} ;
24
23
25
24
/**
@@ -252,9 +251,9 @@ struct Exec {
252
251
discovered_outputs: WorkMap
253
252
}
254
253
255
- struct Work<'self, T> {
256
- prep: &'self Prep<'self> ,
257
- res: Option<Either<T, PortOne<(Exec,T)>>>
254
+ enum Work<'self, T> {
255
+ WorkValue(T) ,
256
+ WorkFromTask(&'self Prep<'self>, PortOne<(Exec, T)>),
258
257
}
259
258
260
259
fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
@@ -426,15 +425,15 @@ impl<'self> Prep<'self> {
426
425
db. prepare ( self . fn_name , & self . declared_inputs )
427
426
} ;
428
427
429
- let res = match cached {
428
+ match cached {
430
429
Some ( ( ref disc_in, ref disc_out, ref res) )
431
430
if self . all_fresh ( "declared input" , & self . declared_inputs ) &&
432
431
self . all_fresh ( "discovered input" , disc_in) &&
433
432
self . all_fresh ( "discovered output" , disc_out) => {
434
433
debug ! ( "Cache hit!" ) ;
435
434
debug ! ( "Trying to decode: %? / %? / %?" ,
436
435
disc_in, disc_out, * res) ;
437
- Left ( json_decode ( * res) )
436
+ Work :: from_value ( json_decode ( * res) )
438
437
}
439
438
440
439
_ => {
@@ -453,10 +452,9 @@ impl<'self> Prep<'self> {
453
452
let v = blk ( & mut exe) ;
454
453
chan. send ( ( exe, v) ) ;
455
454
}
456
- Right ( port)
455
+ Work :: from_task ( self , port)
457
456
}
458
- } ;
459
- Work :: new( self , res)
457
+ }
460
458
}
461
459
}
462
460
@@ -465,16 +463,18 @@ impl<'self, T:Send +
465
463
Decodable < json:: Decoder > >
466
464
Work < ' self , T > { // FIXME(#5121)
467
465
468
- pub fn new( p: & ' self Prep < ' self > , e: Either < T , PortOne < ( Exec , T ) > > ) -> Work < ' self , T > {
469
- Work { prep : p, res : Some ( e) }
466
+ pub fn from_value( elt: T ) -> Work < ' self , T > {
467
+ WorkValue ( elt)
468
+ }
469
+ pub fn from_task( prep: & ' self Prep < ' self > , port: PortOne < ( Exec , T ) > )
470
+ -> Work < ' self , T > {
471
+ WorkFromTask ( prep, port)
470
472
}
471
473
472
474
pub fn unwrap( self ) -> T {
473
- let Work { prep, res } = self ;
474
- match res {
475
- None => fail!( ) ,
476
- Some ( Left ( v) ) => v,
477
- Some ( Right ( port) ) => {
475
+ match self {
476
+ WorkValue ( v) => v,
477
+ WorkFromTask ( prep, port) => {
478
478
let ( exe, v) = port. recv( ) ;
479
479
let s = json_encode( & v) ;
480
480
do prep. ctxt. db. write |db| {
0 commit comments