@@ -34,11 +34,11 @@ use core::mem::replace;
34
34
use core:: iter:: AdditiveIterator ;
35
35
use core:: default:: Default ;
36
36
use alloc:: boxed:: Box ;
37
- use collections:: MutableSeq ;
37
+ use collections:: { MutableSeq , MutableMap } ;
38
38
use collections:: vec:: Vec ;
39
39
use collections:: string:: String ;
40
40
use collections:: str:: { MaybeOwned , Slice , Owned } ;
41
- use std :: collections:: hashmap :: HashMap ;
41
+ use collections:: treemap :: TreeMap ;
42
42
43
43
pub mod states;
44
44
mod interface;
@@ -167,7 +167,7 @@ pub struct Tokenizer<'sink, Sink> {
167
167
temp_buf : String ,
168
168
169
169
/// Record of how many ns we spent in each state, if profiling is enabled.
170
- state_profile : HashMap < states:: State , u64 > ,
170
+ state_profile : TreeMap < states:: State , u64 > ,
171
171
172
172
/// Record of how many ns we spent in the token sink.
173
173
time_in_sink : u64 ,
@@ -201,7 +201,7 @@ impl<'sink, Sink: TokenSink> Tokenizer<'sink, Sink> {
201
201
current_doctype : Doctype :: new ( ) ,
202
202
last_start_tag_name : start_tag_name,
203
203
temp_buf : empty_str ( ) ,
204
- state_profile : HashMap :: new ( ) ,
204
+ state_profile : TreeMap :: new ( ) ,
205
205
time_in_sink : 0 ,
206
206
}
207
207
}
@@ -336,7 +336,17 @@ impl<'sink, Sink: TokenSink> Tokenizer<'sink, Sink> {
336
336
let old_sink = self . time_in_sink ;
337
337
let ( run, mut dt) = time ! ( self . step( ) ) ;
338
338
dt -= ( self . time_in_sink - old_sink) ;
339
- self . state_profile . insert_or_update_with ( state, dt, |_, x| * x += dt) ;
339
+ let new = match self . state_profile . find_mut ( & state) {
340
+ Some ( x) => {
341
+ * x += dt;
342
+ false
343
+ }
344
+ None => true ,
345
+ } ;
346
+ if new {
347
+ // do this here because of borrow shenanigans
348
+ self . state_profile . insert ( state, dt) ;
349
+ }
340
350
if !run { break ; }
341
351
}
342
352
} else {
0 commit comments