Skip to content

Commit f3e4313

Browse files
⚡️ Speed up method AssertCleanup._split_top_level_args by 31% in PR #26 (clean_concolic_tests)
- **Explanation**: - We optimize the character check by using a dictionary, `delimiters`, that maps each character to its corresponding depth adjustment value. This avoids multiple `if-elif` statements and performs a single dictionary lookup. - The loop iterates through each character once, providing an efficient way to split the args string. The overall logic and output remain unchanged.
1 parent 9095ca5 commit f3e4313

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

codeflash/code_utils/concolic_utils.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,16 @@ def _split_top_level_args(self, args_str: str) -> list[str]:
4646
result = []
4747
current = []
4848
depth = 0
49+
delimiters = {",": 0, "(": 1, "[": 1, "{": 1, ")": -1, "]": -1, "}": -1}
4950

5051
for char in args_str:
51-
if char in "([{":
52-
depth += 1
53-
current.append(char)
54-
elif char in ")]}":
55-
depth -= 1
56-
current.append(char)
57-
elif char == "," and depth == 0:
58-
result.append("".join(current).strip())
59-
current = []
52+
if char in delimiters:
53+
depth += delimiters[char]
54+
if char == "," and depth == 0:
55+
result.append("".join(current).strip())
56+
current = []
57+
else:
58+
current.append(char)
6059
else:
6160
current.append(char)
6261

0 commit comments

Comments
 (0)