From 08ef98cc564c3e271b6ca2c9fcf40a601715dbf6 Mon Sep 17 00:00:00 2001 From: mhagger Date: Sun, 4 Apr 2010 15:35:01 +0000 Subject: [PATCH] Add method TimeRange.__lt__(). Patch by: Brian Harring The __lt__() addition may look superfluous, but it's intentional--python sorting relies on __lt__() (just __lt__()); as such for heavily sorted instances a __lt__() was added (TimeRange in this case) for a slight reduction via avoiding cmp() invocation--cmp() requires a nasty search of the various scopes/namespaces and requires native python code interpretting the results; using '<' offloads that into the interpreter itself which can do things far far faster then native python equivalents. git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@5102 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2svn_lib/time_range.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cvs2svn_lib/time_range.py b/cvs2svn_lib/time_range.py index f7dc2349..983b8a8e 100644 --- a/cvs2svn_lib/time_range.py +++ b/cvs2svn_lib/time_range.py @@ -41,4 +41,10 @@ class TimeRange(object): # Sorted by t_max, and break ties using t_min. return cmp(self.t_max, other.t_max) or cmp(self.t_min, other.t_min) + def __lt__(self, other): + c = cmp(self.t_max, other.t_max) + if 0 == c: + return self.t_min < other.t_min + return c < 0 + -- 2.11.4.GIT