mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(semantic): rename Counts to Stats (#5753)
Pure refactor. Just rename the type.
This commit is contained in:
parent
042afa9fd6
commit
667170cbfc
3 changed files with 15 additions and 15 deletions
|
|
@ -22,7 +22,6 @@ use crate::{
|
|||
binder::Binder,
|
||||
checker,
|
||||
class::ClassTableBuilder,
|
||||
counter::Counts,
|
||||
diagnostics::redeclaration,
|
||||
jsdoc::JSDocBuilder,
|
||||
label::UnusedLabels,
|
||||
|
|
@ -30,6 +29,7 @@ use crate::{
|
|||
node::{AstNodes, NodeFlags, NodeId},
|
||||
reference::{Reference, ReferenceFlags, ReferenceId},
|
||||
scope::{Bindings, ScopeFlags, ScopeId, ScopeTree},
|
||||
stats::Stats,
|
||||
symbol::{SymbolFlags, SymbolId, SymbolTable},
|
||||
unresolved_stack::UnresolvedReferencesStack,
|
||||
JSDocFinder, Semantic,
|
||||
|
|
@ -232,10 +232,10 @@ impl<'a> SemanticBuilder<'a> {
|
|||
// Avoiding this growth produces up to 30% perf boost on our benchmarks.
|
||||
// TODO: It would be even more efficient to calculate counts in parser to avoid
|
||||
// this extra AST traversal.
|
||||
let counts = Counts::count(program);
|
||||
self.nodes.reserve(counts.nodes);
|
||||
self.scope.reserve(counts.scopes);
|
||||
self.symbols.reserve(counts.symbols, counts.references);
|
||||
let stats = Stats::count(program);
|
||||
self.nodes.reserve(stats.nodes);
|
||||
self.scope.reserve(stats.scopes);
|
||||
self.symbols.reserve(stats.symbols, stats.references);
|
||||
|
||||
// Visit AST to generate scopes tree etc
|
||||
self.visit_program(program);
|
||||
|
|
@ -243,13 +243,13 @@ impl<'a> SemanticBuilder<'a> {
|
|||
// Check that estimated counts accurately
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let actual_counts = Counts {
|
||||
let actual_stats = Stats {
|
||||
nodes: self.nodes.len(),
|
||||
scopes: self.scope.len(),
|
||||
symbols: self.symbols.len(),
|
||||
references: self.symbols.references.len(),
|
||||
};
|
||||
Counts::assert_accurate(&actual_counts, &counts);
|
||||
Stats::assert_accurate(&actual_stats, &stats);
|
||||
}
|
||||
|
||||
// Checking syntax error on module record requires scope information from the previous AST pass
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ mod binder;
|
|||
mod builder;
|
||||
mod checker;
|
||||
mod class;
|
||||
mod counter;
|
||||
mod diagnostics;
|
||||
mod jsdoc;
|
||||
mod label;
|
||||
|
|
@ -31,6 +30,7 @@ mod module_record;
|
|||
mod node;
|
||||
mod reference;
|
||||
mod scope;
|
||||
mod stats;
|
||||
mod symbol;
|
||||
mod unresolved_stack;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,18 +14,18 @@ use oxc_ast::{
|
|||
use oxc_syntax::scope::{ScopeFlags, ScopeId};
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub(crate) struct Counts {
|
||||
pub(crate) struct Stats {
|
||||
pub nodes: usize,
|
||||
pub scopes: usize,
|
||||
pub symbols: usize,
|
||||
pub references: usize,
|
||||
}
|
||||
|
||||
impl Counts {
|
||||
impl Stats {
|
||||
pub fn count(program: &Program) -> Self {
|
||||
let mut counts = Counts::default();
|
||||
counts.visit_program(program);
|
||||
counts
|
||||
let mut stats = Stats::default();
|
||||
stats.visit_program(program);
|
||||
stats
|
||||
}
|
||||
|
||||
#[cfg_attr(not(debug_assertions), expect(dead_code))]
|
||||
|
|
@ -33,7 +33,7 @@ impl Counts {
|
|||
assert_eq!(actual.nodes, estimated.nodes, "nodes count mismatch");
|
||||
assert_eq!(actual.scopes, estimated.scopes, "scopes count mismatch");
|
||||
assert_eq!(actual.references, estimated.references, "references count mismatch");
|
||||
// `Counts` may overestimate number of symbols, because multiple `BindingIdentifier`s
|
||||
// `Stats` may overestimate number of symbols, because multiple `BindingIdentifier`s
|
||||
// can result in only a single symbol.
|
||||
// e.g. `var x; var x;` = 2 x `BindingIdentifier` but 1 x symbol.
|
||||
// This is not a big problem - allocating a `Vec` with excess capacity is cheap.
|
||||
|
|
@ -48,7 +48,7 @@ impl Counts {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Visit<'a> for Counts {
|
||||
impl<'a> Visit<'a> for Stats {
|
||||
#[inline]
|
||||
fn enter_node(&mut self, _: AstKind<'a>) {
|
||||
self.nodes += 1;
|
||||
Loading…
Reference in a new issue