[Lxml-checkins] r49926 - in lxml/trunk: . src/lxml

scoder at codespeak.net scoder at codespeak.net
Wed Dec 19 12:02:57 CET 2007


Author: scoder
Date: Wed Dec 19 12:02:56 2007
New Revision: 49926

Modified:
   lxml/trunk/   (props changed)
   lxml/trunk/src/lxml/lxml.etree.pyx
   lxml/trunk/src/lxml/xmlid.pxi
Log:
 r3141 at delle:  sbehnel | 2007-12-19 09:13:32 +0100
 eliminated internal calls to ElementTree()


Modified: lxml/trunk/src/lxml/lxml.etree.pyx
==============================================================================
--- lxml/trunk/src/lxml/lxml.etree.pyx	(original)
+++ lxml/trunk/src/lxml/lxml.etree.pyx	Wed Dec 19 12:02:56 2007
@@ -1400,13 +1400,13 @@
         return self._context_node
 
     def __copy__(self):
-        return ElementTree(self._context_node)
+        return _elementTreeFactory(self._doc, self._context_node)
 
     def __deepcopy__(self, memo):
-        if self._context_node is None:
-            return ElementTree()
-        else:
-            return ElementTree( self._context_node.__copy__() )
+        cdef _Element root
+        if self._context_node is not None:
+            root = self._context_node.__copy__()
+        return _elementTreeFactory(None, root)
 
     property docinfo:
         """Information about the document provided by parser and DTD.  This

Modified: lxml/trunk/src/lxml/xmlid.pxi
==============================================================================
--- lxml/trunk/src/lxml/xmlid.pxi	(original)
+++ lxml/trunk/src/lxml/xmlid.pxi	Wed Dec 19 12:02:56 2007
@@ -1,3 +1,5 @@
+cdef object _find_id_attributes
+
 def XMLID(text):
     """Parse the text and return a tuple (root node, ID dictionary).  The root
     node is the same as returned by the XML() function.  The dictionary
@@ -5,10 +7,14 @@
     attributes.  The elements referenced by the ID are stored as dictionary
     values.
     """
+    global _find_id_attributes
+    if _find_id_attributes is None:
+        _find_id_attributes = XPath('//*[string(@id)]')
+
+    # ElementTree compatible implementation: parse and look for 'id' attributes
     root = XML(text)
-    # ElementTree compatible implementation: look for 'id' attributes
     dic = {}
-    for elem in ElementTree(root).xpath('//*[string(@id)]'):
+    for elem in _find_id_attributes(root):
         python.PyDict_SetItem(dic, elem.get('id'), elem)
     return (root, dic)
 
@@ -40,7 +46,7 @@
     """
     cdef _Document doc
     doc = _parseDocument(source, parser)
-    return (ElementTree(doc.getroot()), _IDDict(doc))
+    return (_elementTreeFactory(doc, None), _IDDict(doc))
 
 cdef class _IDDict:
     """A dictionary-like proxy class that mapps ID attributes to elements.


More information about the lxml-checkins mailing list