Optimize regex patterns by pre-compiling them.

This commit is contained in:
QianCY@aliyun 2025-01-26 09:53:18 +08:00
parent e974c6fb1d
commit 26b8d4d7ee
2 changed files with 4 additions and 2 deletions

View File

@ -100,7 +100,8 @@ class LatexPaperSplit():
残存BUG: 未考虑\\\\[length]"""
text = text.replace('\\\\', ' ')
return re.sub(r'\s+', ' ', text)
pattern = re.compile(r'\s+')
return re.sub(pattern, ' ', text)
def read_title_and_abstract(self, txt: str):
try:

View File

@ -333,7 +333,8 @@ def find_main_tex_file(file_manifest, mode):
def rm_comments_inline(content: str):
"""删除掉所有行内注释"""
return re.sub(r"(?<!\\)%.*\n[ \t\r\f\v]*", "", content)
pattern = re.compile(r"(?<!\\)%.*\n[ \t\r\f\v]*")
return re.sub(pattern, "", content)
def rm_comments_block(content: str):