Skip to content

Commit

Permalink
Remove need for regex in TextPosition::matches (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
zsol authored Aug 27, 2023
1 parent 3bb5ba5 commit 7c09b5d
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 7c09b5d

Please sign in to comment.