Newbie Question: can this snippet be optimized?

Hedr Hedr
Wed Jun 25 17:08:00 CEST 2003


Hi Pythonians,

The underlying snippet is copied from minidom.py which is in the XML
package which I am currently using. Cloning nodes seem to take a
considerable amount of time, hence I went looking in the code whether
optimizations could be made. The following snippet contains a for
loop:

    def cloneNode(self, deep):
        clone = Node.cloneNode(self, deep)
        clone._attrs = {}
        clone._attrsNS = {}
        for attr in self._attrs.values():
            node = attr.cloneNode(1)
            clone._attrs[node.name] = node
            clone._attrsNS[(node.namespaceURI, node.localName)] = node
            node.ownerElement = clone
        return clone

I just wondered if this could be optimized (mao, array, whatever) and
if so, how? I do not have much experience with Python, hence the
question.

Thanks for suggestions,

Hedr 




More information about the Python-list mailing list