@@ -19,7 +19,6 @@ use arc::{Arc,RWArc};
1919use treemap:: TreeMap ;
2020use std:: cell:: Cell ;
2121use std:: comm:: { PortOne , oneshot} ;
22- use std:: either:: { Either , Left , Right } ;
2322use std:: { io, os, task} ;
2423
2524/**
@@ -252,9 +251,9 @@ struct Exec {
252251 discovered_outputs: WorkMap
253252}
254253
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)>),
258257}
259258
260259fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
@@ -426,15 +425,15 @@ impl<'self> Prep<'self> {
426425 db. prepare ( self . fn_name , & self . declared_inputs )
427426 } ;
428427
429- let res = match cached {
428+ match cached {
430429 Some ( ( ref disc_in, ref disc_out, ref res) )
431430 if self . all_fresh ( "declared input" , & self . declared_inputs ) &&
432431 self . all_fresh ( "discovered input" , disc_in) &&
433432 self . all_fresh ( "discovered output" , disc_out) => {
434433 debug ! ( "Cache hit!" ) ;
435434 debug ! ( "Trying to decode: %? / %? / %?" ,
436435 disc_in, disc_out, * res) ;
437- Left ( json_decode ( * res) )
436+ Work :: from_value ( json_decode ( * res) )
438437 }
439438
440439 _ => {
@@ -453,10 +452,9 @@ impl<'self> Prep<'self> {
453452 let v = blk ( & mut exe) ;
454453 chan. send ( ( exe, v) ) ;
455454 }
456- Right ( port)
455+ Work :: from_task ( self , port)
457456 }
458- } ;
459- Work :: new( self , res)
457+ }
460458 }
461459}
462460
@@ -465,16 +463,18 @@ impl<'self, T:Send +
465463 Decodable < json:: Decoder > >
466464 Work < ' self , T > { // FIXME(#5121)
467465
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)
470472 }
471473
472474 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) => {
478478 let ( exe, v) = port. recv( ) ;
479479 let s = json_encode( & v) ;
480480 do prep. ctxt. db. write |db| {
0 commit comments