marshallpierce / rust-base64

base64, in rust
Apache License 2.0
616 stars 115 forks source link

Replace internal buffer in decoder with `BufRead` #231

Open Kixunil opened 1 year ago

Kixunil commented 1 year ago

The DecoderReader used an internal buffer for reading which came with a number of disadvantages, such as:

This change removes it and requires BufRead instead. Decoding is implemented on top of fill_buf for larger chunks with fallback to small, stack-allocated buffer for tiny chunks that may appear at boundaries.

To resolve borrowing problems decode_to_buf had to be removed which also enabled decoding bytes directly into internal buffer when the buffer to be filled is small rather than into a temporary buffer which is then copied.

This improves performance of reading by around 7-22% on my machine.

Closes #230

marshallpierce commented 1 year ago

Thanks for the contribution. It will probably take me some time to review it, but I'll get to it when I can.