Skip to content
Snippets Groups Projects
Commit b8cdec92 authored by Erik Johnston's avatar Erik Johnston
Browse files

WheelTimer: Don't scan list, use index.

parent 48b652bc
No related branches found
No related tags found
No related merge requests found
...@@ -46,11 +46,14 @@ class WheelTimer(object): ...@@ -46,11 +46,14 @@ class WheelTimer(object):
then (int): When to return the object strictly after. then (int): When to return the object strictly after.
""" """
then_key = int(then / self.bucket_size) + 1 then_key = int(then / self.bucket_size) + 1
for entry in self.entries:
# Add to first bucket we find. This should gracefully handle inserts if self.entries:
# for times in the past. min_key = self.entries[0].end_key
if entry.end_key >= then_key: max_key = self.entries[-1].end_key
entry.queue.append(obj)
if then_key <= max_key:
# The max here is to protect against inserts for times in the past
self.entries[max(min_key, then_key) - min_key].queue.append(obj)
return return
next_key = int(now / self.bucket_size) + 1 next_key = int(now / self.bucket_size) + 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment