def beforeCommitHookOrdered(self, hook, order, *args, **kws):
if not isinstance(order, IntType):
raise ValueError("An integer value is required "
"for the order argument")
- index = 0
- for o, h, a, k in self._before_commit:
- if order < o:
- index += 1
- self._before_commit.insert(index, (order, hook, args, kws))
+ # `index` goes up by 1 on each append. Then no two tuples can
+ # compare equal, and indeed no more than the `order` and
+ # `index` fields ever get compared when the tuples are compared
+ # (because no two `index` fields are equal).
+ index = len([x for x in self._before_commit if x == order])
+ bisect.insort(self._before_commit, (order, index, hook, args, kws))
Frankly I don't see the point of using bisect if you do a linear pass on the
list first. The original code was clearer and was faster.
If you had a "natural" way of getting the index, then why not. But anyway
this kind of hook list will have only a few elements in it. Optimize later.
Florent Guillaume, Nuxeo (Paris, France) CTO, Director of R&D
+33 1 40 33 71 59 http://nuxeo.com [EMAIL PROTECTED]
For more information about ZODB, see the ZODB Wiki:
ZODB-Dev mailing list - ZODB-Dev@zope.org