diff options
author | Damien George <damien@micropython.org> | 2022-04-20 17:20:07 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-04-22 16:37:02 +1000 |
commit | caaff940a265bd30cca5a271b49e7addaf05ef53 (patch) | |
tree | 7413f84e38feee120173b6ea9d65ed3f3aae79f4 /extmod/uasyncio/task.py | |
parent | 28e7e15c0ad03f406cc5214f22d9a90a560f65c4 (diff) | |
download | micropython-caaff940a265bd30cca5a271b49e7addaf05ef53.tar.gz micropython-caaff940a265bd30cca5a271b49e7addaf05ef53.zip |
extmod/uasyncio: Rename and merge TaskQueue push/pop methods.
These are internal names and can be safely renamed without affecting user
code. push_sorted() and push_head() are merged into a single push()
method, which is already how the C version is implemented. pop_head() is
simply renamed to pop().
The changes are:
- q.push_sorted(task, t) -> q.push(task, t)
- q.push_head(task) -> q.push(task)
- q.pop_head() -> q.pop()
The shorter names and removal of push_head() leads to a code size reduction
of between 40 and 64 bytes on bare-metal targets.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/uasyncio/task.py')
-rw-r--r-- | extmod/uasyncio/task.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/extmod/uasyncio/task.py b/extmod/uasyncio/task.py index 94768b95a4..4ead2a1308 100644 --- a/extmod/uasyncio/task.py +++ b/extmod/uasyncio/task.py @@ -99,17 +99,14 @@ class TaskQueue: def peek(self): return self.heap - def push_sorted(self, v, key): + def push(self, v, key=None): assert v.ph_child is None assert v.ph_next is None v.data = None - v.ph_key = key + v.ph_key = key if key is not None else core.ticks() self.heap = ph_meld(v, self.heap) - def push_head(self, v): - self.push_sorted(v, core.ticks()) - - def pop_head(self): + def pop(self): v = self.heap assert v.ph_next is None self.heap = ph_pairing(v.ph_child) @@ -150,7 +147,7 @@ class Task: raise self.data else: # Put calling task on waiting queue. - self.state.push_head(core.cur_task) + self.state.push(core.cur_task) # Set calling task's data to this task that it waits on, to double-link it. core.cur_task.data = self @@ -171,10 +168,10 @@ class Task: if hasattr(self.data, "remove"): # Not on the main running queue, remove the task from the queue it's on. self.data.remove(self) - core._task_queue.push_head(self) + core._task_queue.push(self) elif core.ticks_diff(self.ph_key, core.ticks()) > 0: # On the main running queue but scheduled in the future, so bring it forward to now. core._task_queue.remove(self) - core._task_queue.push_head(self) + core._task_queue.push(self) self.data = core.CancelledError return True |