Skip to content

Commit 4e5d855

Browse files
committed
memoize clean_alphanumeric with lru_cache
1 parent a9b1ca7 commit 4e5d855

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/hyperbase/parsers/utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
from functools import lru_cache
2+
13
from hyperbase.hyperedge import Hyperedge
24

35

6+
@lru_cache(maxsize=2048)
47
def clean_alphanumeric(s: str) -> str:
5-
"""Lowercase ``s`` and strip every non-alphanumeric character."""
8+
"""Lowercase ``s`` and strip every non-alphanumeric character.
9+
10+
Memoized: this is a pure ``str -> str`` map called many times on the same
11+
small set of token / atom-label strings (e.g. the correctness check runs it
12+
per token per candidate during the parser's correctness search). The cache
13+
is bounded so long-running workers / REPLs don't grow it without limit.
14+
"""
615
return "".join(c.lower() for c in s if c.isalnum())
716

817

0 commit comments

Comments
 (0)