Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions codeflash/code_utils/coverage_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,24 @@ def build_fully_qualified_name(function_name: str, code_context: CodeOptimizatio
def generate_candidates(source_code_path: Path) -> set[str]:
"""Generate all the possible candidates for coverage data based on the source code path."""
candidates = set()
candidates.add(source_code_path.name)
current_path = source_code_path.parent

last_added = source_code_path.name
while current_path != current_path.parent:
candidate_path = (Path(current_path.name) / last_added).as_posix()
# Add the filename as a candidate
name = source_code_path.name
candidates.add(name)

# Precompute parts for efficient candidate path construction
parts = source_code_path.parts
n = len(parts)

# Walk up the directory structure without creating Path objects or repeatedly converting to posix
last_added = name
# Start from the last parent and move up to the root, exclusive (skip the root itself)
for i in range(n - 2, 0, -1):
# Combine the ith part with the accumulated path (last_added)
candidate_path = f"{parts[i]}/{last_added}"
candidates.add(candidate_path)
last_added = candidate_path
current_path = current_path.parent

# Add the absolute posix path as a candidate
candidates.add(source_code_path.as_posix())
return candidates

Expand Down
Loading