Dekkonot / bitbuffer

A binary stream module for packing binary data in pure Lua
https://dekkonot.github.io/bitbuffer/
MIT License
44 stars 11 forks source link

Reimplement writeUnsigned to finish off current byte when buffer isn't aligned #16

Closed Dekkonot closed 4 years ago

Dekkonot commented 4 years ago

At the moment, writeUnsigned calls writeByte several times followed by writeBits. It should instead call writeBits with however many bits is needed to make the buffer aligned, call writeByte with whatever is left, then call writeBits after that.

Benchmarks forthcoming, but I assume this will be substantially faster than the current implementation.

Dekkonot commented 4 years ago

After some testing, I've determined the current method is much faster than the proposed one. Turns out writeByte is fast enough that it doesn't matter and the added overhead of another writeBits is enough to make the function overall much slower.