mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 04:14:59 +00:00
perf: Skip JSON parsing when terminal checking isn't needed
This commit is contained in:
parent
318cc57ffe
commit
ece21315b1
1 changed files with 32 additions and 26 deletions
|
@ -42,36 +42,42 @@ def main():
|
|||
if not line.strip():
|
||||
continue
|
||||
|
||||
event = json.loads(line)
|
||||
# Fast initial check on raw line before JSON parsing
|
||||
raw_line_has_atuin_chars = any(char in line for char in atuin_chars)
|
||||
|
||||
# Only parse JSON if we're checking terminal or need to check
|
||||
if check_terminal or raw_line_has_atuin_chars:
|
||||
event = json.loads(line)
|
||||
|
||||
# For output events, check for potential "Atuin" content
|
||||
if len(event) >= 3 and event[1] == "o":
|
||||
output_text = event[2]
|
||||
|
||||
# For output events, check for potential "Atuin" content
|
||||
if len(event) >= 3 and event[1] == "o":
|
||||
output_text = event[2]
|
||||
# Only start checking terminal if we found Atuin chars
|
||||
if raw_line_has_atuin_chars:
|
||||
check_terminal = True
|
||||
|
||||
# Fast check: if any letters of "Atuin" are in the output
|
||||
if any(char in output_text for char in atuin_chars):
|
||||
check_terminal = True
|
||||
if check_terminal:
|
||||
stream.feed(output_text)
|
||||
|
||||
if check_terminal:
|
||||
stream.feed(output_text)
|
||||
# Check if "Atuin" is visible on screen
|
||||
atuin_visible = False
|
||||
for display_line in screen.display:
|
||||
if "Atuin" in "".join(display_line):
|
||||
atuin_visible = True
|
||||
break
|
||||
|
||||
# If we need to check the terminal, do so
|
||||
if check_terminal:
|
||||
# Check if "Atuin" is visible on screen
|
||||
atuin_visible = False
|
||||
for display_line in screen.display:
|
||||
if "Atuin" in "".join(display_line):
|
||||
atuin_visible = True
|
||||
break
|
||||
|
||||
# Reset flag if Atuin is no longer visible
|
||||
if not atuin_visible:
|
||||
check_terminal = False
|
||||
else:
|
||||
continue # Skip this event if Atuin is visible
|
||||
|
||||
# Write event to output file
|
||||
fout.write(json.dumps(event) + "\n")
|
||||
# Reset flag if Atuin is no longer visible
|
||||
if not atuin_visible:
|
||||
check_terminal = False
|
||||
else:
|
||||
continue # Skip this event if Atuin is visible
|
||||
|
||||
# Write event to output file for non-skipped events
|
||||
fout.write(line)
|
||||
else:
|
||||
# No need to parse JSON if we're not checking terminal
|
||||
fout.write(line)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue