Skip to content

Commit

Permalink
pref: avoid heap alloc for balanced in most cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed May 3, 2024
1 parent 1dba17f commit 86d011e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ edition = "2021"
description = "Lexes CSS modules returning their dependencies metadata"
license = "MIT"

[dependencies]
smallvec = "1.13"

[dev-dependencies]
codspeed-criterion-compat = "2"
criterion = "0.5"
Expand Down
6 changes: 4 additions & 2 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::fmt::Display;

use smallvec::SmallVec;

use crate::lexer::is_white_space;
use crate::lexer::start_ident_sequence;
use crate::lexer::C_ASTERISK;
Expand Down Expand Up @@ -274,7 +276,7 @@ pub struct LexDependencies<'s, D, W> {
scope: Scope<'s>,
block_nesting_level: u32,
allow_import_at_rule: bool,
balanced: Vec<BalancedItem>,
balanced: SmallVec<[BalancedItem; 3]>,
is_next_rule_prelude: bool,
handle_dependency: D,
handle_warning: W,
Expand All @@ -291,7 +293,7 @@ impl<'s, D: HandleDependency<'s>, W: HandleWarning<'s>> LexDependencies<'s, D, W
scope: Scope::TopLevel,
block_nesting_level: 0,
allow_import_at_rule: true,
balanced: Vec::new(),
balanced: Default::default(),
is_next_rule_prelude: true,
handle_dependency,
handle_warning,
Expand Down

0 comments on commit 86d011e

Please sign in to comment.