-
Notifications
You must be signed in to change notification settings - Fork 182
Remove consumed frames in place #1321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,24 @@ | |
| from . import helpers | ||
|
|
||
|
|
||
| class TestFrameBuffer: | ||
| def test_consumed_frames_are_removed_in_place(self) -> None: | ||
| frame = hyperframe.frame.SettingsFrame(0).serialize() | ||
| buffer = h2.frame_buffer.FrameBuffer() | ||
| buffer.max_frame_size = 65535 | ||
| buffer.add_data(frame * 2) | ||
| data = buffer._data | ||
|
|
||
| next(buffer) | ||
|
|
||
| # ``is`` checks object identity (CPython compares ``id(...)`` of both | ||
| # operands): the buffer must still be the very same bytearray object, | ||
| # proving the consumed frame was deleted in place rather than the | ||
| # buffer being replaced by a sliced copy. | ||
| assert buffer._data is data | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a comment to clearly call out that this checks if the object is still the same (internally checked with the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 3a59b4a — the comment now calls out that |
||
| assert buffer._data == frame | ||
|
|
||
|
|
||
| class TestBasicClient: | ||
| """ | ||
| Basic client-side tests. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment here about the behaviour with in-place update without copy, ideally referencing CPython docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 3a59b4a — the comment explains that the slice delete mutates the bytearray in place instead of copying the remainder, with a reference to the mutable-sequence docs (https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types) and to the
ob_startoffset in CPython'sObjects/bytearrayobject.cthat makes front deletes amortized O(1).