1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +02:00

cache _is_separator function

This commit is contained in:
Kelly Brazil
2022-03-24 11:58:13 -07:00
parent 5e6a5068cf
commit 17df5bfcfc
2 changed files with 12 additions and 2 deletions

View File

@ -38,6 +38,12 @@ For example:
good day 12345 good day 12345
hi there abc def 3.14 hi there abc def 3.14
or
foo bar baz
good day 12345
hi there abc def 3.14
etc... etc...
Headers (keys) are converted to snake-case. All values are returned as Headers (keys) are converted to snake-case. All values are returned as
@ -103,6 +109,7 @@ Examples:
] ]
""" """
import re import re
from functools import lru_cache
from typing import List, Dict from typing import List, Dict
import jc.utils import jc.utils
from jc.parsers.universal import sparse_table_parse from jc.parsers.universal import sparse_table_parse
@ -163,9 +170,10 @@ def _strip(string: str) -> str:
string = _rstrip(string) string = _rstrip(string)
return string return string
@lru_cache(maxsize=32)
def _is_separator(line: str) -> bool: def _is_separator(line: str) -> bool:
"""returns true if a table separator line is found""" """returns true if a table separator line is found"""
# This function is cacheable since tables have identical separators
strip_line = line.strip() strip_line = line.strip()
if any(( if any((
strip_line.startswith('') and strip_line.endswith(''), strip_line.startswith('') and strip_line.endswith(''),

View File

@ -93,6 +93,7 @@ Examples:
] ]
""" """
import re import re
from functools import lru_cache
from typing import Iterable, Tuple, List, Dict, Optional from typing import Iterable, Tuple, List, Dict, Optional
import jc.utils import jc.utils
from jc.exceptions import ParseError from jc.exceptions import ParseError
@ -184,9 +185,10 @@ def _table_sniff(string: str) -> str:
# simple tables # simple tables
return 'simple' return 'simple'
@lru_cache(maxsize=32)
def _is_separator(line: str) -> bool: def _is_separator(line: str) -> bool:
"""returns true if a table separator line is found""" """returns true if a table separator line is found"""
# This function is cacheable since tables have identical separators
strip_line = line.strip() strip_line = line.strip()
if any(( if any((
strip_line.startswith('') and strip_line.endswith(''), strip_line.startswith('') and strip_line.endswith(''),