mirror of
git://github.com/kovidgoyal/calibre.git
synced 2025-12-22 07:05:26 +01:00
Speed up docx parsing by caching xpaths
This commit is contained in:
parent
90374d24c4
commit
fab6e1ce7f
1 changed files with 6 additions and 1 deletions
|
|
@ -45,8 +45,13 @@
|
|||
'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…
Reference in a new issue