Skip to content

Commit 17d96d3

Browse files
committed
uasyncio: Optimize reader/writer callbacks with no arguments.
Avoids allocating tuples.
1 parent 18c9084 commit 17d96d3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

uasyncio/uasyncio/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def __init__(self):
1313
def add_reader(self, fd, cb, *args):
1414
if __debug__:
1515
log.debug("add_reader%s", (fd, cb, args))
16-
self.poller.register(fd, select.EPOLLIN | select.EPOLLONESHOT, (cb, args))
16+
if args:
17+
self.poller.register(fd, select.EPOLLIN | select.EPOLLONESHOT, (cb, args))
18+
else:
19+
self.poller.register(fd, select.EPOLLIN | select.EPOLLONESHOT, cb)
1720

1821
def remove_reader(self, fd):
1922
if __debug__:
@@ -23,7 +26,10 @@ def remove_reader(self, fd):
2326
def add_writer(self, fd, cb, *args):
2427
if __debug__:
2528
log.debug("add_writer%s", (fd, cb, args))
26-
self.poller.register(fd, select.EPOLLOUT | select.EPOLLONESHOT, (cb, args))
29+
if args:
30+
self.poller.register(fd, select.EPOLLOUT | select.EPOLLONESHOT, (cb, args))
31+
else:
32+
self.poller.register(fd, select.EPOLLOUT | select.EPOLLONESHOT, cb)
2733

2834
def remove_writer(self, fd):
2935
if __debug__:
@@ -48,8 +54,11 @@ def wait(self, delay):
4854
#log.debug("epoll result: %s", res)
4955
for cb, ev in res:
5056
if __debug__:
51-
log.debug("Calling IO callback: %s%s", cb[0], cb[1])
52-
cb[0](*cb[1])
57+
log.debug("Calling IO callback: %r", cb)
58+
if isinstance(cb, tuple):
59+
cb[0](*cb[1])
60+
else:
61+
cb()
5362

5463

5564
class StreamReader:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy