1010
1111use bitvec:: BitMatrix ;
1212use fx:: FxHashMap ;
13+ use sync:: Lock ;
1314use rustc_serialize:: { Encodable , Encoder , Decodable , Decoder } ;
1415use stable_hasher:: { HashStable , StableHasher , StableHasherResult } ;
15- use std:: cell:: RefCell ;
1616use std:: fmt:: Debug ;
1717use std:: hash:: Hash ;
1818use std:: mem;
1919
2020
2121#[ derive( Clone , Debug ) ]
22- pub struct TransitiveRelation < T : Clone + Debug + Eq + Hash + Clone > {
22+ pub struct TransitiveRelation < T : Clone + Debug + Eq + Hash > {
2323 // List of elements. This is used to map from a T to a usize.
2424 elements : Vec < T > ,
2525
@@ -32,14 +32,14 @@ pub struct TransitiveRelation<T: Clone + Debug + Eq + Hash + Clone> {
3232
3333 // This is a cached transitive closure derived from the edges.
3434 // Currently, we build it lazilly and just throw out any existing
35- // copy whenever a new edge is added. (The RefCell is to permit
35+ // copy whenever a new edge is added. (The Lock is to permit
3636 // the lazy computation.) This is kind of silly, except for the
3737 // fact its size is tied to `self.elements.len()`, so I wanted to
3838 // wait before building it up to avoid reallocating as new edges
3939 // are added with new elements. Perhaps better would be to ask the
4040 // user for a batch of edges to minimize this effect, but I
4141 // already wrote the code this way. :P -nmatsakis
42- closure : RefCell < Option < BitMatrix > > ,
42+ closure : Lock < Option < BitMatrix > > ,
4343}
4444
4545#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable , Debug ) ]
@@ -51,13 +51,13 @@ struct Edge {
5151 target : Index ,
5252}
5353
54- impl < T : Clone + Debug + Eq + Hash + Clone > TransitiveRelation < T > {
54+ impl < T : Clone + Debug + Eq + Hash > TransitiveRelation < T > {
5555 pub fn new ( ) -> TransitiveRelation < T > {
5656 TransitiveRelation {
5757 elements : vec ! [ ] ,
5858 map : FxHashMap ( ) ,
5959 edges : vec ! [ ] ,
60- closure : RefCell :: new ( None ) ,
60+ closure : Lock :: new ( None ) ,
6161 }
6262 }
6363
@@ -72,7 +72,7 @@ impl<T: Clone + Debug + Eq + Hash + Clone> TransitiveRelation<T> {
7272 fn add_index ( & mut self , a : T ) -> Index {
7373 let & mut TransitiveRelation {
7474 ref mut elements,
75- ref closure,
75+ ref mut closure,
7676 ref mut map,
7777 ..
7878 } = self ;
@@ -82,7 +82,7 @@ impl<T: Clone + Debug + Eq + Hash + Clone> TransitiveRelation<T> {
8282 elements. push ( a) ;
8383
8484 // if we changed the dimensions, clear the cache
85- * closure. borrow_mut ( ) = None ;
85+ * closure. get_mut ( ) = None ;
8686
8787 Index ( elements. len ( ) - 1 )
8888 } )
@@ -122,7 +122,7 @@ impl<T: Clone + Debug + Eq + Hash + Clone> TransitiveRelation<T> {
122122 self . edges . push ( edge) ;
123123
124124 // added an edge, clear the cache
125- * self . closure . borrow_mut ( ) = None ;
125+ * self . closure . get_mut ( ) = None ;
126126 }
127127 }
128128
@@ -443,7 +443,7 @@ impl<T> Decodable for TransitiveRelation<T>
443443 . enumerate ( )
444444 . map ( |( index, elem) | ( elem. clone ( ) , Index ( index) ) )
445445 . collect ( ) ;
446- Ok ( TransitiveRelation { elements, edges, map, closure : RefCell :: new ( None ) } )
446+ Ok ( TransitiveRelation { elements, edges, map, closure : Lock :: new ( None ) } )
447447 } )
448448 }
449449}
0 commit comments