+
Skip to content

Conversation

asder8215
Copy link
Contributor

This PR makes a slight change to the existing code in uucore/features/ringbuffer.rs.

Currently, the RingBuffer<T> struct's new() function creates the ringbuffer with an empty VecDeque<T> that does not reserve a certain capacity for elements. Internally, VecDeque<T> resizes and copies the element of its buffer to a new double sized buffer when it's at capacity and push_back() call is invoked. For a fixed-size ringbuffer, instead of paying the cost of resizing the buffer at every power of 2, we can pay the cost of directly allocating exactly the memory we want from the requested size in the new() function upfront to avoid resizing. It also removes the need for a size field in the RingBuffer<T> struct because VecDeque<T> has a capacity() method that tells you how many items the buffer can contain without reallocating.

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@cakebaker cakebaker merged commit 2884718 into uutils:main Oct 13, 2025
121 checks passed
@cakebaker
Copy link
Contributor

Thanks for your PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载