Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Grow buffers exponentially, not one byte at a time (#121)
* Grow buffers exponentially, not one byte at a time To check if a TranscodingStream is eof, it first checks if it has any unused bytes in its buffer. If not, it will attempt to fill the buffer, and only return true if no bytes were filled. If there is no margin in the buffer to fill, it will call `makemargin(buffer, 1)` to ensure at least 1 byte of space. In the happy case, this will remove used up bytes. Unfortunately, buffers do never move data pointed to by their mark. So, when no space is available due to the entire buffer being filled up with marked data, the buffer will grow one byte at a time in a loop until the data fills. This is unacceptable as megabytes of data can theoretically be marked. This commit changes the growth behaviour to request at least half the buffer's length in the margin. In most cases, this will do nothing. But in the unhappy case mentioned above, it will cause the buffer to grow expoentially, until a proper size is quickly reached. * Address suggestions
- Loading branch information