1212
1313use cast;
1414use cmp:: Eq ;
15- use dvec;
1615use libc;
1716use option;
1817use prelude:: * ;
@@ -35,11 +34,11 @@ impl Eq for LocalData {
3534 pure fn ne ( & self , other : & @LocalData ) -> bool { !( * self ) . eq ( other) }
3635}
3736
38- // We use dvec because it's the best data structure in core. If TLS is used
39- // heavily in future, this could be made more efficient with a proper map.
37+ // If TLS is used heavily in future, this could be made more efficient with a
38+ // proper map.
4039type TaskLocalElement = ( * libc:: c_void , * libc:: c_void , LocalData ) ;
4140// Has to be a pointer at outermost layer; the foreign call returns void *.
42- type TaskLocalMap = @dvec :: DVec < Option < TaskLocalElement > > ;
41+ type TaskLocalMap = @mut ~ [ Option < TaskLocalElement > ] ;
4342
4443extern fn cleanup_task_local_map ( map_ptr : * libc:: c_void ) {
4544 unsafe {
@@ -60,17 +59,21 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
6059 // drop when they finish. No "re-storing after modifying" is needed.
6160 let map_ptr = rt:: rust_get_task_local_data ( task) ;
6261 if map_ptr. is_null ( ) {
63- let map: TaskLocalMap = @dvec :: DVec ( ) ;
62+ let map: TaskLocalMap = @mut ~ [ ] ;
6463 // Use reinterpret_cast -- transmute would take map away from us also.
6564 rt:: rust_set_task_local_data (
6665 task, cast:: reinterpret_cast ( & map) ) ;
6766 rt:: rust_task_local_data_atexit ( task, cleanup_task_local_map) ;
6867 // Also need to reference it an extra time to keep it for now.
69- cast:: bump_box_refcount ( map) ;
68+ let nonmut = cast:: transmute :: < TaskLocalMap ,
69+ @~[ Option < TaskLocalElement > ] > ( map) ;
70+ cast:: bump_box_refcount ( nonmut) ;
7071 map
7172 } else {
7273 let map = cast:: transmute ( map_ptr) ;
73- cast:: bump_box_refcount ( map) ;
74+ let nonmut = cast:: transmute :: < TaskLocalMap ,
75+ @~[ Option < TaskLocalElement > ] > ( map) ;
76+ cast:: bump_box_refcount ( nonmut) ;
7477 map
7578 }
7679}
@@ -118,7 +121,7 @@ unsafe fn local_get_helper<T:Durable>(
118121 let data: @T = cast:: transmute ( data_ptr) ;
119122 cast:: bump_box_refcount ( data) ;
120123 if do_pop {
121- ( * map) . set_elt ( index, None ) ;
124+ map[ index] = None ;
122125 }
123126 data
124127 }
@@ -159,13 +162,13 @@ pub unsafe fn local_set<T:Durable>(
159162 Some ( ( index, _old_data_ptr) ) => {
160163 // Key already had a value set, _old_data_ptr, whose reference
161164 // will get dropped when the local_data box is overwritten.
162- ( * map) . set_elt ( index, new_entry) ;
165+ map[ index] = new_entry;
163166 }
164167 None => {
165168 // Find an empty slot. If not, grow the vector.
166169 match ( * map) . position ( |x| x. is_none ( ) ) {
167- Some ( empty_index) => ( * map) . set_elt ( empty_index, new_entry) ,
168- None => ( * map) . push ( new_entry)
170+ Some ( empty_index) => { map[ empty_index] = new_entry; }
171+ None => { map. push ( new_entry) ; }
169172 }
170173 }
171174 }
0 commit comments