Optimize regex patterns by pre-compiling them.
This commit is contained in:
parent
e974c6fb1d
commit
26b8d4d7ee
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in New Issue