Skip to content

Commit 759a94a

Browse files
committed
refactor(semantic): Stats store counts as u32
1 parent c886d8c commit 759a94a

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

crates/oxc_semantic/src/builder.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -233,21 +233,22 @@ impl<'a> SemanticBuilder<'a> {
233233
// TODO: It would be even more efficient to calculate counts in parser to avoid
234234
// this extra AST traversal.
235235
let stats = Stats::count(program);
236-
self.nodes.reserve(stats.nodes);
237-
self.scope.reserve(stats.scopes);
238-
self.symbols.reserve(stats.symbols, stats.references);
236+
self.nodes.reserve(stats.nodes as usize);
237+
self.scope.reserve(stats.scopes as usize);
238+
self.symbols.reserve(stats.symbols as usize, stats.references as usize);
239239

240240
// Visit AST to generate scopes tree etc
241241
self.visit_program(program);
242242

243243
// Check that estimated counts accurately
244244
#[cfg(debug_assertions)]
245245
{
246+
#[allow(clippy::cast_possible_truncation)]
246247
let actual_stats = Stats {
247-
nodes: self.nodes.len(),
248-
scopes: self.scope.len(),
249-
symbols: self.symbols.len(),
250-
references: self.symbols.references.len(),
248+
nodes: self.nodes.len() as u32,
249+
scopes: self.scope.len() as u32,
250+
symbols: self.symbols.len() as u32,
251+
references: self.symbols.references.len() as u32,
251252
};
252253
Stats::assert_accurate(&actual_stats, &stats);
253254
}

crates/oxc_semantic/src/stats.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use oxc_syntax::scope::{ScopeFlags, ScopeId};
1515

1616
#[derive(Default, Debug)]
1717
pub(crate) struct Stats {
18-
pub nodes: usize,
19-
pub scopes: usize,
20-
pub symbols: usize,
21-
pub references: usize,
18+
pub nodes: u32,
19+
pub scopes: u32,
20+
pub symbols: u32,
21+
pub references: u32,
2222
}
2323

2424
impl Stats {

0 commit comments

Comments
 (0)