From 02a6625a0076368014e351303810ecaa9765b266 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 13 Nov 2016 14:51:04 +0300 Subject: [PATCH] uasyncio.core: Introduce "trailing _" functions which avoid arg un/packing. They just take tuple of arguments instead of *args. In most cases, that will be () singleton. --- uasyncio.core/uasyncio/core.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/uasyncio.core/uasyncio/core.py b/uasyncio.core/uasyncio/core.py index bd8b240b..4bb0da88 100644 --- a/uasyncio.core/uasyncio/core.py +++ b/uasyncio.core/uasyncio/core.py @@ -29,14 +29,19 @@ class EventLoop: def call_later(self, delay, callback, *args): self.call_at(time.ticks_add(self.time(), int(delay * 1000)), callback, *args) - def call_later_ms(self, delay, callback, *args): - self.call_at(time.ticks_add(self.time(), delay), callback, *args) + def call_later_ms_(self, delay, callback, args=()): + self.call_at_(time.ticks_add(self.time(), delay), callback, args) def call_at(self, time, callback, *args): if __debug__: log.debug("Scheduling %s", (time, callback, args)) heapq.heappush(self.q, (time, callback, args), True) + def call_at_(self, time, callback, args=()): + if __debug__ and DEBUG: + log.debug("Scheduling %s", (time, callback, args)) + heapq.heappush(self.q, (time, callback, args), True) + def wait(self, delay): # Default wait implementation, to be overriden in subclasses # with IO scheduling @@ -106,7 +111,7 @@ class EventLoop: if __debug__: log.debug("Coroutine finished: %s", cb) continue - self.call_later_ms(delay, cb, *args) + self.call_later_ms_(delay, cb, args) def run_until_complete(self, coro): def _run_and_stop():