File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -278,18 +278,28 @@ def closest_matching_file_function_name(
278278
279279 Returns:
280280 Tuple of (file_path, function) for closest match, or None if no matches found
281+
281282 """
282283 min_distance = 4
283284 closest_match = None
284285 closest_file = None
285286
286- qualified_fn_to_find = qualified_fn_to_find .lower ()
287+ # Lowercase once before loop for better performance
288+ qualified_fn_to_find_lower = qualified_fn_to_find .lower ()
289+
290+ # Cache levenshtein_distance locally for improved lookup speed
291+ _levenshtein = levenshtein_distance
292+
293+ # Use for-loop without unnecessary assignments in the inner loop
287294
288295 for file_path , functions in found_fns .items ():
289296 for function in functions :
290297 # Compare either full qualified name or just function name
291298 fn_name = function .qualified_name .lower ()
292- dist = levenshtein_distance (qualified_fn_to_find , fn_name )
299+ # If the absolute length difference is already >= min_distance, skip calculation
300+ if abs (len (qualified_fn_to_find_lower ) - len (fn_name )) >= min_distance :
301+ continue
302+ dist = _levenshtein (qualified_fn_to_find_lower , fn_name )
293303
294304 if dist < min_distance :
295305 min_distance = dist
You can’t perform that action at this time.
0 commit comments