From 7c09b5d046824309ccb7cc2dec3899f0016f2a3a Mon Sep 17 00:00:00 2001 From: Zsolt Dollenstein Date: Sun, 27 Aug 2023 16:29:20 +0100 Subject: [PATCH] Remove need for regex in TextPosition::matches (#1002) --- native/libcst/src/tokenizer/text_position/mod.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/native/libcst/src/tokenizer/text_position/mod.rs b/native/libcst/src/tokenizer/text_position/mod.rs index fece9e3d3..42a7b6820 100644 --- a/native/libcst/src/tokenizer/text_position/mod.rs +++ b/native/libcst/src/tokenizer/text_position/mod.rs @@ -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; } @@ -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