summaryrefslogtreecommitdiff
path: root/AK/CircularBuffer.cpp
AgeCommit message (Collapse)Author
2023-05-09AK: Add `CircularBuffer::flush_to_stream`Lucas CHOLLET
In a similar fashion to what have been done with `fill_from_stream`, this new method allows to write CircularBuffer's data to a Stream without additional copies.
2023-04-14AK: Efficiently resize CircularBuffer seekback copy distanceTim Schumacher
Previously, if we copied the last byte for a length of 100, we'd recalculate the read span 100 times and memmove one byte 100 times, which resulted in a lot of overhead. Now, if we know that we have two consecutive copies of the data, we just extend the distance to cover both copies, which halves the number of times that we recalculate the span and actually call memmove. This takes the running time of the attached benchmark case from 150ms down to 15ms.
2023-04-05AK+LibCompress: Break when seekback copying to a full CircularBufferTim Schumacher
Otherwise, we just end up infinitely looping while waiting for more space in the destination.
2023-04-05AK: Report copied bytes when seekback copying from CircularBufferTim Schumacher
Otherwise, we have no way of determining whether our copy was truncated by accident.
2023-04-05AK: Properly limit the internal seekback span for CircularBufferTim Schumacher
I was originally thinking in the wrong direction when adding this limit, we can at most read from the buffer until we reach the current write head. Since that write head is the reference point for the distance, we need to limit ourselves to that instead of the seekback limit (which is the maximum of how far back the distance can be).
2023-03-31AK+LibCompress: Remove the Deflate back-reference intermediate bufferTimothy Flynn
Instead of reading bytes from the output stream into a buffer, just to immediately write them back out, we can skip the middle-man and copy the bytes directly into the output buffer.
2023-03-30AK: Remove arbitrary 1 KB limit when filling a BufferedStream's bufferTimothy Flynn
When reading, we currently only fill a BufferedStream's buffer when it is empty, and only with 1 KB of data. This means that while the buffer defaults to a size of 16 KB, at least 15 KB is always unused.
2023-03-21AK: Expose the seekback limit of CircularBufferTim Schumacher
2023-01-15AK+Test: Fix a logic error in `CircularBuffer::offset_of()`Lucas CHOLLET
This error was introduced by 9a7accdd and had a significant impact on `BufferedFile` behavior. Hence, we started seeing crash in test262. By itself, the issue was a wrong calculation of the internal reading spans when using the `read` and `until` parameters. Which can lead to at worse crash in VERIFY and at least weird behaviors as missed needles or detections out of bounds. It was also accompanied by an erroneous test. This patch fixes the bug, the test and also provides more tests.
2023-01-14AK: Add an optional starting offset to `CircularBuffer::offset_of`Lucas CHOLLET
This parameter allows to start searching after an offset. For example, to resume a search. It is unfortunately a breaking change in API so this patch also modifies one user and one test.
2023-01-13AK: Add `CircularBuffer::read_with_seekback`Tim Schumacher
2022-12-31AK: Add `CircularBuffer`Lucas CHOLLET
The class is very similar to `CircularDuplexStream` in its behavior. Main differences are that `CircularBuffer`: - does not inherit from `AK::Stream` - uses `ErrorOr` for its API - is heap allocated (and OOM-Safe) This patch also add some tests.