From 26b8d4d7ee57a3db7231285327ba71ae27bc5935 Mon Sep 17 00:00:00 2001 From: "QianCY@aliyun" Date: Sun, 26 Jan 2025 09:53:18 +0800 Subject: [PATCH] Optimize regex patterns by pre-compiling them. --- crazy_functions/latex_fns/latex_actions.py | 3 ++- crazy_functions/latex_fns/latex_toolbox.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crazy_functions/latex_fns/latex_actions.py b/crazy_functions/latex_fns/latex_actions.py index fc4a2dba..bc750e62 100644 --- a/crazy_functions/latex_fns/latex_actions.py +++ b/crazy_functions/latex_fns/latex_actions.py @@ -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: diff --git a/crazy_functions/latex_fns/latex_toolbox.py b/crazy_functions/latex_fns/latex_toolbox.py index eaddb0e4..40ff41e7 100644 --- a/crazy_functions/latex_fns/latex_toolbox.py +++ b/crazy_functions/latex_fns/latex_toolbox.py @@ -333,7 +333,8 @@ def find_main_tex_file(file_manifest, mode): def rm_comments_inline(content: str): """删除掉所有行内注释""" - return re.sub(r"(?