Speed up docx parsing by caching xpaths

This commit is contained in:
Kovid Goyal 2013-05-11 17:34:20 +05:30
parent 90374d24c4
commit fab6e1ce7f

View File

@ -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)