File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77
88from __future__ import annotations
99
10+ import fnmatch
11+ import re
1012from dataclasses import dataclass , field
1113from typing import TYPE_CHECKING , Any , Protocol , runtime_checkable
1214
@@ -172,6 +174,23 @@ class FunctionFilterCriteria:
172174 min_lines : int | None = None
173175 max_lines : int | None = None
174176
177+ def __post_init__ (self ) -> None :
178+ """Pre-compile regex patterns from glob patterns for faster matching."""
179+ self ._include_regexes = [re .compile (fnmatch .translate (p )) for p in self .include_patterns ]
180+ self ._exclude_regexes = [re .compile (fnmatch .translate (p )) for p in self .exclude_patterns ]
181+
182+ def matches_include_patterns (self , name : str ) -> bool :
183+ """Check if name matches any include pattern."""
184+ if not self ._include_regexes :
185+ return True
186+ return any (regex .match (name ) for regex in self ._include_regexes )
187+
188+ def matches_exclude_patterns (self , name : str ) -> bool :
189+ """Check if name matches any exclude pattern."""
190+ if not self ._exclude_regexes :
191+ return False
192+ return any (regex .match (name ) for regex in self ._exclude_regexes )
193+
175194
176195@dataclass
177196class ReferenceInfo :
Original file line number Diff line number Diff line change 1616from codeflash .models .function_types import FunctionParent
1717
1818if TYPE_CHECKING :
19+ from tree_sitter import Node
20+
1921 from codeflash .languages .java .parser import JavaAnalyzer , JavaMethodNode
2022
2123logger = logging .getLogger (__name__ )
@@ -136,18 +138,14 @@ def _should_include_method(
136138 return False
137139
138140 # Check include patterns
139- if criteria .include_patterns :
140- import fnmatch
141-
142- if not any (fnmatch .fnmatch (method .name , pattern ) for pattern in criteria .include_patterns ):
143- return False
141+ if not criteria .matches_include_patterns (method .name ):
142+ return False
144143
145144 # Check exclude patterns
146- if criteria .exclude_patterns :
147- import fnmatch
145+ if criteria .matches_exclude_patterns ( method . name ) :
146+ return False
148147
149- if any (fnmatch .fnmatch (method .name , pattern ) for pattern in criteria .exclude_patterns ):
150- return False
148+ # Check require_return - void methods don't have return values
151149
152150 # Check require_return - void methods don't have return values
153151 if criteria .require_return :
@@ -203,7 +201,7 @@ def discover_test_methods(file_path: Path, analyzer: JavaAnalyzer | None = None)
203201
204202
205203def _walk_tree_for_test_methods (
206- node ,
204+ node : Node ,
207205 source_bytes : bytes ,
208206 file_path : Path ,
209207 test_methods : list [FunctionToOptimize ],
You can’t perform that action at this time.
0 commit comments