gh-141968: Use take_bytes to simplify and remove copy from pyrepl BaseEventQueue#149852
gh-141968: Use take_bytes to simplify and remove copy from pyrepl BaseEventQueue#149852lgeiger wants to merge 2 commits into
take_bytes to simplify and remove copy from pyrepl BaseEventQueue#149852Conversation
…repl `BaseEventQueue`
|
cc @cmaloney |
| return not self.events | ||
|
|
||
| def flush_buf(self) -> bytearray: | ||
| def flush_buf(self) -> bytes: |
There was a problem hiding this comment.
Maybe this method is redundant now?
There was a problem hiding this comment.
I'm happy to remove the function. For now I kept it to keep the diff small. But happy to remove it and just use self.buf.take_bytes() instead. Let me know what you prefer.
There was a problem hiding this comment.
👍 to removing, this is only used three places and I don't think after this change test_flush_buf is adding a lot of value
1b0d030 to
bf42a7b
Compare
cmaloney
left a comment
There was a problem hiding this comment.
Happy to see .take_bytes() helping speed up more code!
| old = self.buf | ||
| self.buf = bytearray() | ||
| return old | ||
| return self.buf.take_bytes() # type: ignore[attr-defined, no-any-return] |
There was a problem hiding this comment.
the attr-defined shouldn't be needed here / if the type checker supports 3.15+ the attribute is always defined; not sure about the rest (I'd remove unless the in-repository mypy check requires)
| return not self.events | ||
|
|
||
| def flush_buf(self) -> bytearray: | ||
| def flush_buf(self) -> bytes: |
There was a problem hiding this comment.
👍 to removing, this is only used three places and I don't think after this change test_flush_buf is adding a lot of value
This PR uses
bytearray.take_bytesto simplify pyrepl'sBaseEventQueue.flush_bufand remove copies fromBaseEventQueue.push