jamesmunns / postcard

A no_std + serde compatible message library for Rust
Apache License 2.0
943 stars 91 forks source link

Optimize varint decode #62

Closed bugadani closed 2 years ago

bugadani commented 2 years ago

It's not necessary to update a check value in every cycle - it's only relevant while processing the last encoded byte.

Obligatory godbolt link, this time with x86 asm because I was lazy: https://rust.godbolt.org/z/hMh3qW67h

netlify[bot] commented 2 years ago

Deploy Preview for cute-starship-2d9c9b canceled.

Name Link
Latest commit 88ec6e083b3acf231f7d1add4ce7f0b64d4a972a
Latest deploy log https://app.netlify.com/sites/cute-starship-2d9c9b/deploys/62b18e7fc0314800084d0d73
bugadani commented 2 years ago

Technically, in the last iteration it's unnecessary to mask the continuation bit (it's either zero or the check value catches the invalid data anyway), but that would make the impl a lot bulkier so I haven't done it.