Merge pull request #1729 from dvolodin7/patch-1
_Timeout.__lt__ speedup
This commit is contained in:
commit
c26ccd97af
|
@ -966,26 +966,24 @@ class _Timeout(object):
|
||||||
"""An IOLoop timeout, a UNIX timestamp and a callback"""
|
"""An IOLoop timeout, a UNIX timestamp and a callback"""
|
||||||
|
|
||||||
# Reduce memory overhead when there are lots of pending callbacks
|
# Reduce memory overhead when there are lots of pending callbacks
|
||||||
__slots__ = ['deadline', 'callback', 'tiebreaker']
|
__slots__ = ['deadline', 'callback', 'tdeadline']
|
||||||
|
|
||||||
def __init__(self, deadline, callback, io_loop):
|
def __init__(self, deadline, callback, io_loop):
|
||||||
if not isinstance(deadline, numbers.Real):
|
if not isinstance(deadline, numbers.Real):
|
||||||
raise TypeError("Unsupported deadline %r" % deadline)
|
raise TypeError("Unsupported deadline %r" % deadline)
|
||||||
self.deadline = deadline
|
self.deadline = deadline
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.tiebreaker = next(io_loop._timeout_counter)
|
self.tdeadline = (deadline, next(io_loop._timeout_counter))
|
||||||
|
|
||||||
# Comparison methods to sort by deadline, with object id as a tiebreaker
|
# Comparison methods to sort by deadline, with object id as a tiebreaker
|
||||||
# to guarantee a consistent ordering. The heapq module uses __le__
|
# to guarantee a consistent ordering. The heapq module uses __le__
|
||||||
# in python2.5, and __lt__ in 2.6+ (sort() and most other comparisons
|
# in python2.5, and __lt__ in 2.6+ (sort() and most other comparisons
|
||||||
# use __lt__).
|
# use __lt__).
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
return ((self.deadline, self.tiebreaker) <
|
return self.tdeadline < other.tdeadline
|
||||||
(other.deadline, other.tiebreaker))
|
|
||||||
|
|
||||||
def __le__(self, other):
|
def __le__(self, other):
|
||||||
return ((self.deadline, self.tiebreaker) <=
|
return self.tdeadline <= other.tdeadline
|
||||||
(other.deadline, other.tiebreaker))
|
|
||||||
|
|
||||||
|
|
||||||
class PeriodicCallback(object):
|
class PeriodicCallback(object):
|
||||||
|
|
Loading…
Reference in New Issue