[Zope-Checkins] SVN: Zope/trunk/ Optimized the `OFS.Traversable.getPhysicalPath` method to avoid excessive amounts of method calls. Thx to Nikolay Kim from Enfold
Hanno Schlichting
hannosch at hannosch.eu
Thu Jul 14 04:16:09 EDT 2011
Log message for revision 122213:
Optimized the `OFS.Traversable.getPhysicalPath` method to avoid excessive amounts of method calls. Thx to Nikolay Kim from Enfold
Changed:
U Zope/trunk/doc/CHANGES.rst
U Zope/trunk/src/OFS/Traversable.py
-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst 2011-07-14 07:16:04 UTC (rev 122212)
+++ Zope/trunk/doc/CHANGES.rst 2011-07-14 08:16:08 UTC (rev 122213)
@@ -19,6 +19,9 @@
Features Added
++++++++++++++
+- Optimized the `OFS.Traversable.getPhysicalPath` method to avoid excessive
+ amounts of method calls.
+
- During startup open a connection to every configured database, to ensure all
of them can indeed be accessed. This avoids surprises during runtime when
traversal to some database mountpoint could fail as the underlying storage
Modified: Zope/trunk/src/OFS/Traversable.py
===================================================================
--- Zope/trunk/src/OFS/Traversable.py 2011-07-14 07:16:04 UTC (rev 122212)
+++ Zope/trunk/src/OFS/Traversable.py 2011-07-14 08:16:08 UTC (rev 122213)
@@ -114,14 +114,47 @@
access this object again later, for example in a copy/paste operation.
getPhysicalRoot() and getPhysicalPath() are designed to operate
together.
+
+ This implementation is optimized to avoid excessive amounts of function
+ calls while walking up from an object on a deep level.
"""
- path = (self.getId(),)
+ try:
+ id = self.id
+ except AttributeError:
+ id = self.getId()
+ else:
+ if id is None:
+ id = self.getId()
p = aq_parent(aq_inner(self))
+ if p is None:
+ return (id, )
- if p is not None:
- path = p.getPhysicalPath() + path
+ path = [id]
+ func = self.getPhysicalPath.im_func
+ while p is not None:
+ if func is p.getPhysicalPath.im_func:
+ try:
+ pid = p.id
+ except AttributeError:
+ pid = p.getId()
+ else:
+ if pid is None:
+ pid = p.getId()
+ path.insert(0, pid)
+ try:
+ p = p.__parent__
+ except AttributeError:
+ p = None
+ else:
+ if IApplication.providedBy(p):
+ path.insert(0, '')
+ path = tuple(path)
+ else:
+ path = p.getPhysicalPath() + tuple(path)
+ break
+
return path
security.declarePrivate('unrestrictedTraverse')
More information about the Zope-Checkins
mailing list