@@ -17,8 +17,8 @@ use core::prelude::*;
17
17
use metadata:: cstore;
18
18
use metadata:: decoder;
19
19
20
+ use core:: hashmap:: linear:: LinearMap ;
20
21
use core:: vec;
21
- use std:: oldmap;
22
22
use std;
23
23
use syntax:: { ast, attr} ;
24
24
use syntax:: parse:: token:: ident_interner;
@@ -27,7 +27,7 @@ use syntax::parse::token::ident_interner;
27
27
// local crate numbers (as generated during this session). Each external
28
28
// crate may refer to types in other external crates, and each has their
29
29
// own crate numbers.
30
- pub type cnum_map = oldmap :: HashMap < ast:: crate_num , ast:: crate_num > ;
30
+ pub type cnum_map = @ mut LinearMap < ast:: crate_num , ast:: crate_num > ;
31
31
32
32
pub struct crate_metadata {
33
33
name : @~str ,
@@ -37,7 +37,7 @@ pub struct crate_metadata {
37
37
}
38
38
39
39
pub struct CStore {
40
- priv metas : oldmap :: HashMap < ast:: crate_num , @crate_metadata > ,
40
+ priv metas : LinearMap < ast:: crate_num , @crate_metadata > ,
41
41
priv extern_mod_crate_map : extern_mod_crate_map ,
42
42
priv used_crate_files : ~[ Path ] ,
43
43
priv used_libraries : ~[ ~str ] ,
@@ -46,111 +46,102 @@ pub struct CStore {
46
46
}
47
47
48
48
// Map from node_id's of local extern mod statements to crate numbers
49
- type extern_mod_crate_map = oldmap :: HashMap < ast:: node_id , ast:: crate_num > ;
49
+ type extern_mod_crate_map = LinearMap < ast:: node_id , ast:: crate_num > ;
50
50
51
51
pub fn mk_cstore ( intr : @ident_interner ) -> CStore {
52
- let meta_cache = oldmap:: HashMap ( ) ;
53
- let crate_map = oldmap:: HashMap ( ) ;
54
52
return CStore {
55
- metas : meta_cache ,
56
- extern_mod_crate_map : crate_map ,
53
+ metas : LinearMap :: new ( ) ,
54
+ extern_mod_crate_map : LinearMap :: new ( ) ,
57
55
used_crate_files : ~[ ] ,
58
56
used_libraries : ~[ ] ,
59
57
used_link_args : ~[ ] ,
60
58
intr : intr
61
59
} ;
62
60
}
63
61
64
- pub fn get_crate_data ( cstore : @ mut CStore , cnum : ast:: crate_num )
62
+ pub fn get_crate_data ( cstore : & CStore , cnum : ast:: crate_num )
65
63
-> @crate_metadata {
66
- return cstore. metas . get ( & cnum) ;
64
+ return * cstore. metas . get ( & cnum) ;
67
65
}
68
66
69
- pub fn get_crate_hash ( cstore : @ mut CStore , cnum : ast:: crate_num ) -> @~str {
67
+ pub fn get_crate_hash ( cstore : & CStore , cnum : ast:: crate_num ) -> @~str {
70
68
let cdata = get_crate_data ( cstore, cnum) ;
71
69
decoder:: get_crate_hash ( cdata. data )
72
70
}
73
71
74
- pub fn get_crate_vers ( cstore : @ mut CStore , cnum : ast:: crate_num ) -> @~str {
72
+ pub fn get_crate_vers ( cstore : & CStore , cnum : ast:: crate_num ) -> @~str {
75
73
let cdata = get_crate_data ( cstore, cnum) ;
76
74
decoder:: get_crate_vers ( cdata. data )
77
75
}
78
76
79
- pub fn set_crate_data ( cstore : @ mut CStore ,
77
+ pub fn set_crate_data ( cstore : & mut CStore ,
80
78
cnum : ast:: crate_num ,
81
79
data : @crate_metadata ) {
82
- let metas = cstore. metas ;
83
- metas. insert ( cnum, data) ;
80
+ cstore. metas . insert ( cnum, data) ;
84
81
}
85
82
86
- pub fn have_crate_data ( cstore : @ mut CStore , cnum : ast:: crate_num ) -> bool {
83
+ pub fn have_crate_data ( cstore : & CStore , cnum : ast:: crate_num ) -> bool {
87
84
cstore. metas . contains_key ( & cnum)
88
85
}
89
86
90
- pub fn iter_crate_data ( cstore : @ mut CStore ,
87
+ pub fn iter_crate_data ( cstore : & CStore ,
91
88
i : & fn ( ast:: crate_num , @crate_metadata ) ) {
92
- let metas = cstore. metas ;
93
- for metas. each |& k, & v| {
89
+ for cstore. metas. each |& ( & k, & v) | {
94
90
i( k, v) ;
95
91
}
96
92
}
97
93
98
- pub fn add_used_crate_file ( cstore : @mut CStore , lib : & Path ) {
99
- let cstore = & mut * cstore;
94
+ pub fn add_used_crate_file ( cstore : & mut CStore , lib : & Path ) {
100
95
if !vec:: contains ( cstore. used_crate_files , lib) {
101
96
cstore. used_crate_files . push ( copy * lib) ;
102
97
}
103
98
}
104
99
105
- pub fn get_used_crate_files ( cstore : @ mut CStore ) -> ~[ Path ] {
100
+ pub fn get_used_crate_files ( cstore : & CStore ) -> ~[ Path ] {
106
101
return /*bad*/ copy cstore. used_crate_files ;
107
102
}
108
103
109
- pub fn add_used_library ( cstore : @ mut CStore , lib : @~str ) -> bool {
104
+ pub fn add_used_library ( cstore : & mut CStore , lib : @~str ) -> bool {
110
105
fail_unless ! ( * lib != ~"") ;
111
106
112
- let cstore = & mut * cstore;
113
107
if cstore. used_libraries . contains ( & * lib) { return false ; }
114
108
cstore. used_libraries . push ( /*bad*/ copy * lib) ;
115
109
true
116
110
}
117
111
118
- pub fn get_used_libraries ( cstore : @ mut CStore ) -> ~[ ~str ] {
112
+ pub fn get_used_libraries ( cstore : & CStore ) -> ~[ ~str ] {
119
113
/*bad*/ copy cstore. used_libraries
120
114
}
121
115
122
- pub fn add_used_link_args ( cstore : @ mut CStore , args : & str ) {
116
+ pub fn add_used_link_args ( cstore : & mut CStore , args : & str ) {
123
117
for args. each_split_char( ' ' ) |s| {
124
118
cstore. used_link_args . push ( s. to_owned ( ) ) ;
125
119
}
126
120
}
127
121
128
- pub fn get_used_link_args ( cstore : @ mut CStore ) -> ~[ ~str ] {
122
+ pub fn get_used_link_args ( cstore : & CStore ) -> ~[ ~str ] {
129
123
/*bad*/ copy cstore. used_link_args
130
124
}
131
125
132
- pub fn add_extern_mod_stmt_cnum ( cstore : @ mut CStore ,
126
+ pub fn add_extern_mod_stmt_cnum ( cstore : & mut CStore ,
133
127
emod_id : ast:: node_id ,
134
128
cnum : ast:: crate_num ) {
135
- let extern_mod_crate_map = cstore. extern_mod_crate_map ;
136
- extern_mod_crate_map. insert ( emod_id, cnum) ;
129
+ cstore. extern_mod_crate_map . insert ( emod_id, cnum) ;
137
130
}
138
131
139
- pub fn find_extern_mod_stmt_cnum ( cstore : @ mut CStore ,
132
+ pub fn find_extern_mod_stmt_cnum ( cstore : & CStore ,
140
133
emod_id : ast:: node_id )
141
134
-> Option < ast:: crate_num > {
142
- let extern_mod_crate_map = cstore. extern_mod_crate_map ;
143
- extern_mod_crate_map. find ( & emod_id)
135
+ cstore. extern_mod_crate_map . find ( & emod_id) . map_consume ( |x| * x)
144
136
}
145
137
146
138
// returns hashes of crates directly used by this crate. Hashes are sorted by
147
139
// (crate name, crate version, crate hash) in lexicographic order (not semver)
148
- pub fn get_dep_hashes ( cstore : @ mut CStore ) -> ~[ ~str ] {
140
+ pub fn get_dep_hashes ( cstore : & CStore ) -> ~[ ~str ] {
149
141
struct crate_hash { name : @~str , vers : @~str , hash : @~str }
150
142
let mut result = ~[ ] ;
151
143
152
- let extern_mod_crate_map = cstore. extern_mod_crate_map ;
153
- for extern_mod_crate_map. each_value |& cnum| {
144
+ for cstore. extern_mod_crate_map. each_value |& cnum| {
154
145
let cdata = cstore:: get_crate_data ( cstore, cnum) ;
155
146
let hash = decoder:: get_crate_hash ( cdata. data ) ;
156
147
let vers = decoder:: get_crate_vers ( cdata. data ) ;
0 commit comments