BurntSushi / byteorder

Rust library for reading/writing numbers in big-endian and little-endian.
The Unlicense
981 stars 143 forks source link

Simplify pack_size() and pack_size128() #199

Closed moubctez closed 1 year ago

moubctez commented 1 year ago

pack_size() and pack_size128() can be written in more compact form, taking advantage of CPU capabilities of counting leading zeros in a number. I've quickly checked that pack_size() on Aarch64 it shrinks down from 27 to 5 opcodes, and on X86_64: from 26 to 8.