Skip to content

Commit

Permalink
refactor(codegen): replace daachorse with string match for annotati…
Browse files Browse the repository at this point in the history
…on comment
  • Loading branch information
Boshen committed Nov 1, 2024
1 parent e86bbad commit 8e9b135
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 21 deletions.
8 changes: 0 additions & 8 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ console_error_panic_hook = "0.1.7"
convert_case = "0.6.0"
cow-utils = "0.1.3"
criterion2 = { version = "1.1.1", default-features = false }
daachorse = { version = "1.0.0" }
dashmap = "6.1.0"
encoding_rs = "0.8.34"
encoding_rs_io = "0.1.7"
Expand Down
2 changes: 0 additions & 2 deletions crates/oxc_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ oxc_syntax = { workspace = true, features = ["to_js_string"] }
assert-unchecked = { workspace = true }
bitflags = { workspace = true }
cow-utils = { workspace = true }
daachorse = { workspace = true }
nonmax = { workspace = true }
once_cell = { workspace = true }
rustc-hash = { workspace = true }

[dev-dependencies]
Expand Down
14 changes: 4 additions & 10 deletions crates/oxc_codegen/src/comment.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
use daachorse::DoubleArrayAhoCorasick;
use once_cell::sync::Lazy;
use rustc_hash::FxHashMap;

use oxc_ast::{Comment, CommentKind};
use oxc_syntax::identifier::is_line_terminator;

use crate::Codegen;

static ANNOTATION_MATCHER: Lazy<DoubleArrayAhoCorasick<usize>> = Lazy::new(|| {
let patterns = vec!["#__NO_SIDE_EFFECTS__", "@__NO_SIDE_EFFECTS__", "@__PURE__", "#__PURE__"];

DoubleArrayAhoCorasick::new(patterns).unwrap()
});

pub(crate) type CommentsMap = FxHashMap</* attached_to */ u32, Vec<Comment>>;

impl<'a> Codegen<'a> {
Expand Down Expand Up @@ -113,8 +105,10 @@ impl<'a> Codegen<'a> {
}

fn is_annotation_comment(&self, comment: &Comment) -> bool {
let comment_content = comment.span.source_text(self.source_text);
ANNOTATION_MATCHER.find_iter(comment_content).count() != 0
let s = comment.span.source_text(self.source_text);
s.split_once("__PURE__")
.or_else(|| s.split_once("__NO_SIDE_EFFECTS__"))
.is_some_and(|(s, _)| s.ends_with(['@', '#']))
}

pub(crate) fn print_annotation_comments(&mut self, node_start: u32) {
Expand Down

0 comments on commit 8e9b135

Please sign in to comment.