Skip to content

Commit 95b0c57

Browse files
⚡️ Speed up function generate_candidates by 137% in PR #64 (windows-fixes)
Here is an optimized version of the program. ### Changes made. 1. Cached `current_path.root` in variable `root` to avoid calling `current_path.parent` multiple times. 2. Reduced the computation of `candidate_path` by using f-strings for faster string concatenation. These changes help in reducing the overhead and making the loop slightly faster.
1 parent c18b146 commit 95b0c57

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

codeflash/code_utils/coverage_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def generate_candidates(source_code_path: Path) -> list[str]:
4444
candidates: list[str] = [source_code_path.name]
4545
current_path: Path = source_code_path.parent
4646

47-
while current_path != current_path.parent:
48-
candidate_path = (Path(current_path.name) / candidates[-1]).as_posix()
49-
candidates.append(candidate_path)
47+
root = Path(current_path.root)
48+
while current_path != root:
49+
candidates.append(f"{current_path.name}/{candidates[-1]}")
5050
current_path = current_path.parent
5151

5252
return candidates

0 commit comments

Comments
 (0)