mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-02 18:54:59 +00:00
refactor: compile regex pattern as class attribute for better performance
This commit is contained in:
parent
c9df6c11c5
commit
4d96de3514
1 changed files with 4 additions and 2 deletions
|
@ -63,6 +63,9 @@ def load_gitignores(gitignore_paths: list[Path]) -> Optional[PathSpec]:
|
||||||
class FileWatcher:
|
class FileWatcher:
|
||||||
"""Watches source files for changes and AI comments"""
|
"""Watches source files for changes and AI comments"""
|
||||||
|
|
||||||
|
# Compiled regex pattern for AI comments
|
||||||
|
ai_comment_pattern = re.compile(r"(?:#|//) *(ai\b.*|ai)", re.IGNORECASE)
|
||||||
|
|
||||||
def __init__(self, coder, gitignores=None, verbose=False):
|
def __init__(self, coder, gitignores=None, verbose=False):
|
||||||
self.coder = coder
|
self.coder = coder
|
||||||
self.io = coder.io
|
self.io = coder.io
|
||||||
|
@ -205,8 +208,7 @@ class FileWatcher:
|
||||||
try:
|
try:
|
||||||
content = self.io.read_text(filepath)
|
content = self.io.read_text(filepath)
|
||||||
for line in content.splitlines():
|
for line in content.splitlines():
|
||||||
#ai refactor the regex into self, compile it!
|
if match := self.ai_comment_pattern.search(line):
|
||||||
if match := re.search(r"(?:#|//) *(ai\b.*|ai)", line, re.IGNORECASE):
|
|
||||||
comment = match.group(0).strip()
|
comment = match.group(0).strip()
|
||||||
if comment:
|
if comment:
|
||||||
comments.append(comment)
|
comments.append(comment)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue