Skip to content
Closed
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
9 changes: 6 additions & 3 deletions src/algorithms/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ def decorator(func: Callable) -> Callable:
cache: dict[str, tuple[Any, float]] = {}

def wrapper(*args, **kwargs) -> Any:
key_parts = [repr(arg) for arg in args]
key_parts.extend(f"{k}:{repr(v)}" for k, v in sorted(kwargs.items()))
key = ":".join(key_parts)
# Optimize key construction by using tuple for args and a tuple of sorted items for kwargs
# This avoids unnecessary repr() string conversions and string joins
if kwargs:
key = (args, tuple(sorted(kwargs.items())))
else:
key = (args, None)

current_time = time.time()

Expand Down