Newbie Question: can this snippet be optimized?

H

Hedr

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
 
R

Raymond Hettinger

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.


Try applying psyco.bind() to see if you can
get a substantial speed-up.


Raymond Hettinger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top