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:
-                break
-            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[1] for x in self._before_commit if x[1] == 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

--
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:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to