From d1a83e6986470d2db81474bb7fd3eadada78b0a4 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 29 Mar 2013 09:04:35 -0700 Subject: std: add Encoder::emit_map and Decoder::read_map --- src/libstd/workcache.rs | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'src/libstd/workcache.rs') diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index f477a8c9f91..90f10ea5054 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -137,7 +137,11 @@ pub impl WorkKey { } } -type WorkMap = LinearMap; +struct WorkMap(LinearMap); + +impl WorkMap { + fn new() -> WorkMap { WorkMap(LinearMap::new()) } +} impl Encodable for WorkMap { fn encode(&self, s: &S) { @@ -153,7 +157,7 @@ impl Encodable for WorkMap { impl Decodable for WorkMap { fn decode(d: &D) -> WorkMap { let v : ~[(WorkKey,~str)] = Decodable::decode(d); - let mut w = LinearMap::new(); + let mut w = WorkMap::new(); for v.each |&(k, v)| { w.insert(copy k, copy v); } @@ -235,7 +239,7 @@ fn json_encode>(t: &T) -> ~str { } // FIXME(#5121) -fn json_decode>>(s: &str) -> T { +fn json_decode>(s: &str) -> T { do io::with_str_reader(s) |rdr| { let j = result::unwrap(json::from_reader(rdr)); Decodable::decode(&json::Decoder(j)) @@ -260,18 +264,25 @@ pub impl Context { fn new(db: @Mut, lg: @Mut, cfg: @json::Object) -> Context { - Context{db: db, logger: lg, cfg: cfg, freshness: LinearMap::new()} + Context { + db: db, + logger: lg, + cfg: cfg, + freshness: LinearMap::new() + } } fn prep + - Decodable>>( // FIXME(#5121) + Decodable>( // FIXME(#5121) @self, fn_name:&str, blk: &fn(@Mut)->Work) -> Work { - let p = @Mut(Prep {ctxt: self, - fn_name: fn_name.to_owned(), - declared_inputs: LinearMap::new()}); + let p = @Mut(Prep { + ctxt: self, + fn_name: fn_name.to_owned(), + declared_inputs: WorkMap::new() + }); blk(p) } } @@ -283,7 +294,7 @@ trait TPrep { fn all_fresh(&self, cat:&str, map:&WorkMap) -> bool; fn exec + - Decodable>>( // FIXME(#5121) + Decodable>( // FIXME(#5121) &self, blk: ~fn(&Exec) -> T) -> Work; } @@ -324,7 +335,7 @@ impl TPrep for @Mut { fn exec + - Decodable>>( // FIXME(#5121) + Decodable>( // FIXME(#5121) &self, blk: ~fn(&Exec) -> T) -> Work { let mut bo = Some(blk); @@ -349,8 +360,10 @@ impl TPrep for @Mut { let blk = blk.unwrap(); let chan = Cell(chan); do task::spawn || { - let exe = Exec{discovered_inputs: LinearMap::new(), - discovered_outputs: LinearMap::new()}; + let exe = Exec { + discovered_inputs: WorkMap::new(), + discovered_outputs: WorkMap::new(), + }; let chan = chan.take(); let v = blk(&exe); send_one(chan, (exe, v)); @@ -365,7 +378,7 @@ impl TPrep for @Mut { pub impl + - Decodable>> Work { // FIXME(#5121) + Decodable> Work { // FIXME(#5121) fn new(p: @Mut, e: Either>) -> Work { Work { prep: p, res: Some(e) } } @@ -374,7 +387,7 @@ pub impl + - Decodable>>( // FIXME(#5121) + Decodable>( // FIXME(#5121) w: Work) -> T { let mut ww = w; let mut s = None; -- cgit 1.4.1-3-g733a5