From f9eed2340d88bc46f27c3c5c7ce4987a98b9bcb3 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 5 Dec 2015 22:23:10 +0200 Subject: [PATCH] uasyncio.core: Optimize for syscalls with single args. Avoids allocating argument tuples. --- uasyncio.core/uasyncio/core.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/uasyncio.core/uasyncio/core.py b/uasyncio.core/uasyncio/core.py index d6be7303..2821fe60 100644 --- a/uasyncio.core/uasyncio/core.py +++ b/uasyncio.core/uasyncio/core.py @@ -71,8 +71,8 @@ class EventLoop: ret = cb.send(*args) if __debug__: log.debug("Coroutine %s yield result: %s", cb, ret) - if isinstance(ret, SysCall): - arg = ret.args[0] + if isinstance(ret, SysCall1): + arg = ret.arg if isinstance(ret, Sleep): delay = arg elif isinstance(ret, IORead): @@ -121,22 +121,28 @@ class SysCall: def handle(self): raise NotImplementedError -class Sleep(SysCall): +# Optimized syscall with 1 arg +class SysCall1(SysCall): + + def __init__(self, arg): + self.arg = arg + +class Sleep(SysCall1): pass -class StopLoop(SysCall): +class StopLoop(SysCall1): pass -class IORead(SysCall): +class IORead(SysCall1): pass -class IOWrite(SysCall): +class IOWrite(SysCall1): pass -class IOReadDone(SysCall): +class IOReadDone(SysCall1): pass -class IOWriteDone(SysCall): +class IOWriteDone(SysCall1): pass