Skip to content

Commit

Permalink
Remove need for regex in TextPosition::matches
Browse files Browse the repository at this point in the history
  • Loading branch information
zsol committed Aug 27, 2023
1 parent 75b6331 commit 1db5f0b
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions native/libcst/src/tokenizer/text_position/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ use std::fmt;
use crate::tokenizer::debug_utils::EllipsisDebug;
use char_width::NewlineNormalizedCharWidths;

thread_local! {
static CR_OR_LF_RE: Regex = Regex::new(r"[\r\n]").expect("regex");
}

pub trait TextPattern {
fn match_len(&self, text: &str) -> Option<usize>;
}
Expand Down Expand Up @@ -99,7 +95,7 @@ impl<'t> TextPosition<'t> {
match match_len {
Some(match_len) => {
assert!(
!CR_OR_LF_RE.with(|r| r.is_match(&rest_of_text[..match_len])),
!rest_of_text[..match_len].contains(|x| x == '\r' || x == '\n'),
"matches pattern must not match a newline",
);
true
Expand Down

0 comments on commit 1db5f0b

Please sign in to comment.