Skip to content

Commit

Permalink
perf: reduce deadline creation
Browse files Browse the repository at this point in the history
  • Loading branch information
x42005e1f committed Nov 8, 2024
1 parent 276e92d commit a8b49e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/aiologic/locks/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ def wait_for(self, /, predicate, timeout=None):
def notify(self, /, count=1, *, deadline=None):
waiters = self.__waiters

if deadline is None:
deadline = self.__timer()

notified = 0

while waiters and notified != count:
Expand All @@ -200,6 +197,9 @@ def notify(self, /, count=1, *, deadline=None):
else:
event, time = token

if deadline is None:
deadline = self.__timer()

if time <= deadline:
if event.set():
notified += 1
Expand All @@ -216,9 +216,6 @@ def notify(self, /, count=1, *, deadline=None):
def notify_all(self, /, *, deadline=None):
waiters = self.__waiters

if deadline is None:
deadline = self.__timer()

notified = 0

while waiters:
Expand All @@ -229,6 +226,9 @@ def notify_all(self, /, *, deadline=None):
else:
event, time = token

if deadline is None:
deadline = self.__timer()

if time <= deadline:
if event.set():
notified += 1
Expand Down
12 changes: 6 additions & 6 deletions src/aiologic/locks/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ def __wakeup(self, /, deadline=None):
waiters = self.__waiters
is_unset = self.__is_unset

if deadline is None:
deadline = self.__timer()

while waiters:
try:
token = waiters[0]
Expand All @@ -290,6 +287,9 @@ def __wakeup(self, /, deadline=None):
else:
event, marker, time, _ = token

if deadline is None:
deadline = self.__timer()

if time <= deadline and marker is not is_unset.get(None):
token[3] = deadline

Expand Down Expand Up @@ -468,9 +468,6 @@ def __get(self, /):
def __wakeup(self, /, deadline=None):
waiters = self.__waiters

if deadline is None:
deadline = self.__timer()

while waiters:
try:
token = waiters[0]
Expand All @@ -479,6 +476,9 @@ def __wakeup(self, /, deadline=None):
else:
event, marker, time, _ = token

if deadline is None:
deadline = self.__timer()

if time <= deadline and marker is not self.__get():
token[3] = deadline

Expand Down

0 comments on commit a8b49e1

Please sign in to comment.