Commit 61538262 authored by admuc's avatar admuc

speed up lru_cache

parent f57c6f54
......@@ -16,6 +16,10 @@ from codecs import lookup
from copy import copy as ccopy
from csv import reader as csv_reader
from decimal import Decimal, ROUND_HALF_UP
try:
from functools import lru_cache
except (NameError, ModuleNotFoundError, ImportError):
pass
from io import StringIO as io_StringIO
from itertools import repeat as itertools_repeat
from locale import getdefaultlocale
......@@ -4249,6 +4253,7 @@ class Macros:
if callouts ^ (m.name != 'callout'):
result = m.subs(result)
return result
def isnext(self):
"""Return matching macro if block macro is next on reader."""
reader.skip_blank_lines()
......@@ -4261,6 +4266,7 @@ class Macros:
return m
return False
#@lru_cache(65536)
def match(self, prefix, name, text):
"""Return re match object matching 'text' with macro type 'prefix',
macro name 'name'."""
......@@ -4273,6 +4279,11 @@ class Macros:
if re.match(name, mo.group('name')):
return mo
return None
try:
#lru_cache not implemented in Python < 3.3
match = lru_cache(65536)(match) # 2**16 = 65536
except (NameError, ModuleNotFoundError, ImportError):
pass
def extract_passthroughs(self, text, prefix=''):
""" Extract the passthrough text and replace with temporary
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment