mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Speed up docx parsing by caching xpaths
This commit is contained in:
parent
90374d24c4
commit
fab6e1ce7f
@ -45,8 +45,13 @@ namespaces = {
|
||||
'dcterms': 'http://purl.org/dc/terms/'
|
||||
}
|
||||
|
||||
xpath_cache = {}
|
||||
|
||||
def XPath(expr):
|
||||
return X(expr, namespaces=namespaces)
|
||||
ans = xpath_cache.get(expr, None)
|
||||
if ans is None:
|
||||
xpath_cache[expr] = ans = X(expr, namespaces=namespaces)
|
||||
return ans
|
||||
|
||||
def is_tag(x, q):
|
||||
tag = getattr(x, 'tag', x)
|
||||
|
Loading…
x
Reference in New Issue
Block a user