1
- use std:: collections:: hash_map:: Entry ;
2
1
use std:: fs;
3
2
use std:: iter:: Peekable ;
4
3
use std:: path:: Path ;
5
4
use std:: str:: Chars ;
6
5
7
- use rustc_data_structures:: fx:: FxHashMap ;
6
+ use rustc_data_structures:: fx:: { FxIndexMap , IndexEntry } ;
8
7
use rustc_errors:: DiagCtxtHandle ;
9
8
10
9
#[ cfg( test) ]
11
10
mod tests;
12
11
13
12
#[ derive( Debug ) ]
14
13
pub ( crate ) struct CssPath {
15
- pub ( crate ) rules : FxHashMap < String , String > ,
16
- pub ( crate ) children : FxHashMap < String , CssPath > ,
14
+ pub ( crate ) rules : FxIndexMap < String , String > ,
15
+ pub ( crate ) children : FxIndexMap < String , CssPath > ,
17
16
}
18
17
19
18
/// When encountering a `"` or a `'`, returns the whole string, including the quote characters.
@@ -120,10 +119,10 @@ fn parse_rules(
120
119
content : & str ,
121
120
selector : String ,
122
121
iter : & mut Peekable < Chars < ' _ > > ,
123
- paths : & mut FxHashMap < String , CssPath > ,
122
+ paths : & mut FxIndexMap < String , CssPath > ,
124
123
) -> Result < ( ) , String > {
125
- let mut rules = FxHashMap :: default ( ) ;
126
- let mut children = FxHashMap :: default ( ) ;
124
+ let mut rules = FxIndexMap :: default ( ) ;
125
+ let mut children = FxIndexMap :: default ( ) ;
127
126
128
127
loop {
129
128
// If the parent isn't a "normal" CSS selector, we only expect sub-selectors and not CSS
@@ -146,10 +145,10 @@ fn parse_rules(
146
145
return Err ( format ! ( "Found empty value for rule `{rule}` in selector `{selector}`" ) ) ;
147
146
}
148
147
match rules. entry ( rule) {
149
- Entry :: Occupied ( mut o) => {
148
+ IndexEntry :: Occupied ( mut o) => {
150
149
* o. get_mut ( ) = value;
151
150
}
152
- Entry :: Vacant ( v) => {
151
+ IndexEntry :: Vacant ( v) => {
153
152
v. insert ( value) ;
154
153
}
155
154
}
@@ -159,7 +158,7 @@ fn parse_rules(
159
158
}
160
159
161
160
match paths. entry ( selector) {
162
- Entry :: Occupied ( mut o) => {
161
+ IndexEntry :: Occupied ( mut o) => {
163
162
let v = o. get_mut ( ) ;
164
163
for ( key, value) in rules. into_iter ( ) {
165
164
v. rules . insert ( key, value) ;
@@ -168,7 +167,7 @@ fn parse_rules(
168
167
v. children . insert ( sel, child) ;
169
168
}
170
169
}
171
- Entry :: Vacant ( v) => {
170
+ IndexEntry :: Vacant ( v) => {
172
171
v. insert ( CssPath { rules, children } ) ;
173
172
}
174
173
}
@@ -178,7 +177,7 @@ fn parse_rules(
178
177
pub ( crate ) fn parse_selectors (
179
178
content : & str ,
180
179
iter : & mut Peekable < Chars < ' _ > > ,
181
- paths : & mut FxHashMap < String , CssPath > ,
180
+ paths : & mut FxIndexMap < String , CssPath > ,
182
181
) -> Result < ( ) , String > {
183
182
let mut selector = String :: new ( ) ;
184
183
@@ -202,17 +201,17 @@ pub(crate) fn parse_selectors(
202
201
203
202
/// The entry point to parse the CSS rules. Every time we encounter a `{`, we then parse the rules
204
203
/// inside it.
205
- pub ( crate ) fn load_css_paths ( content : & str ) -> Result < FxHashMap < String , CssPath > , String > {
204
+ pub ( crate ) fn load_css_paths ( content : & str ) -> Result < FxIndexMap < String , CssPath > , String > {
206
205
let mut iter = content. chars ( ) . peekable ( ) ;
207
- let mut paths = FxHashMap :: default ( ) ;
206
+ let mut paths = FxIndexMap :: default ( ) ;
208
207
209
208
parse_selectors ( content, & mut iter, & mut paths) ?;
210
209
Ok ( paths)
211
210
}
212
211
213
212
pub ( crate ) fn get_differences (
214
- origin : & FxHashMap < String , CssPath > ,
215
- against : & FxHashMap < String , CssPath > ,
213
+ origin : & FxIndexMap < String , CssPath > ,
214
+ against : & FxIndexMap < String , CssPath > ,
216
215
v : & mut Vec < String > ,
217
216
) {
218
217
for ( selector, entry) in origin. iter ( ) {
@@ -235,7 +234,7 @@ pub(crate) fn get_differences(
235
234
236
235
pub ( crate ) fn test_theme_against < P : AsRef < Path > > (
237
236
f : & P ,
238
- origin : & FxHashMap < String , CssPath > ,
237
+ origin : & FxIndexMap < String , CssPath > ,
239
238
dcx : DiagCtxtHandle < ' _ > ,
240
239
) -> ( bool , Vec < String > ) {
241
240
let against = match fs:: read_to_string ( f)
0 commit comments