Skip to content

Commit d10ee94

Browse files
authored
Merge pull request #16 from KyleKing/claude/performance-optimizations-0164SPN6fj1DYzbYkt1rMYWt
1 parent 0466775 commit d10ee94

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

tail_jsonl/_private/core.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import json
66
import logging
7-
from copy import copy
87
from dataclasses import dataclass
98
from typing import Any
109

@@ -27,18 +26,17 @@ def _dot_pop(data: dict, key: str) -> str | None: # type: ignore[type-arg]
2726
return None
2827

2928

30-
def _pop_key(data: dict, keys: list[str], fallback: str) -> Any: # type: ignore[type-arg]
31-
"""Return result of recursively popping each key while searching for a match."""
32-
try:
33-
key = keys.pop(0)
34-
except IndexError:
29+
def _pop_key(data: dict, keys: list[str], index: int, fallback: str) -> Any: # type: ignore[type-arg]
30+
"""Return result of recursively searching for a matching key."""
31+
if index >= len(keys):
3532
return fallback
36-
return _dot_pop(data, key) or _pop_key(data, keys, fallback)
33+
key = keys[index]
34+
return _dot_pop(data, key) or _pop_key(data, keys, index + 1, fallback)
3735

3836

3937
def pop_key(data: dict, keys: list[str], fallback: str) -> Any: # type: ignore[type-arg]
4038
"""Return the first key in the data or default to the fallback."""
41-
return _pop_key(data, copy(keys), fallback)
39+
return _pop_key(data, keys, 0, fallback)
4240

4341

4442
@dataclass
@@ -65,7 +63,8 @@ def print_record(line: str, console: Console, config: Config) -> None:
6563
"""Format and print the record."""
6664
try:
6765
record = Record.from_line(json.loads(line), config=config)
68-
except Exception:
66+
except (json.JSONDecodeError, ValueError, KeyError, TypeError, AttributeError):
67+
# Handle JSON parsing errors, missing keys, type errors, and attribute access issues
6968
console.print(line.rstrip(), markup=False, highlight=False) # Print the unmodified line
7069
return
7170

0 commit comments

Comments
 (0)