[Lxml-checkins] r46718 - lxml/trunk/src/lxml
scoder at codespeak.net
scoder at codespeak.net
Tue Sep 18 12:48:00 CEST 2007
Author: scoder
Date: Tue Sep 18 12:48:00 2007
New Revision: 46718
Modified:
lxml/trunk/src/lxml/xslt.pxi
Log:
avoid XPath instantiation on startup
Modified: lxml/trunk/src/lxml/xslt.pxi
==============================================================================
--- lxml/trunk/src/lxml/xslt.pxi (original)
+++ lxml/trunk/src/lxml/xslt.pxi Tue Sep 18 12:48:00 2007
@@ -598,10 +598,16 @@
cdef object _REPLACE_PI_HREF
_REPLACE_PI_HREF = _RE_PI_HREF.sub
-cdef XPath _findStylesheetByID
-_findStylesheetByID = XPath(
- "//xsl:stylesheet[@xml:id = $id]",
- {"xsl":"http://www.w3.org/1999/XSL/Transform"})
+cdef XPath __findStylesheetByID
+__findStylesheetByID = None
+
+cdef _findStylesheetByID(_Document doc, id):
+ global __findStylesheetByID
+ if __findStylesheetByID is None:
+ __findStylesheetByID = XPath(
+ "//xsl:stylesheet[@xml:id = $id]",
+ {"xsl" : "http://www.w3.org/1999/XSL/Transform"})
+ return __findStylesheetByID(doc, id=id)
cdef class _XSLTProcessingInstruction(PIBase):
def parseXSL(self, parser=None):
@@ -647,7 +653,7 @@
return _elementTreeFactory(result_node._doc, result_node)
# try XPath search
- root = _findStylesheetByID(self._doc, id=funicode(c_href))
+ root = _findStylesheetByID(self._doc, funicode(c_href))
if not root:
raise ValueError, "reference to non-existing embedded stylesheet"
elif len(root) > 1:
More information about the lxml-checkins
mailing list