-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Seek first bytes lengths before seek bits for __deku_input #502
Conversation
Benchmark for 78ed86bClick to view benchmark
|
deku-derive/src/macros/deku_read.rs
Outdated
if bytes != 0 { | ||
use ::#crate_::no_std_io::Seek; | ||
use ::#crate_::no_std_io::SeekFrom; | ||
if let Err(e) = __deku_reader.seek(SeekFrom::Current(i64::try_from(bytes).unwrap())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we handle the error from i64::try_from
? else we should expect
instead of unwrap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah, the seek_*
code has the same problem.
deku-derive/src/macros/deku_read.rs
Outdated
if bytes != 0 { | ||
use ::#crate_::no_std_io::Seek; | ||
use ::#crate_::no_std_io::SeekFrom; | ||
if let Err(e) = __deku_reader.seek(SeekFrom::Current(i64::try_from(bytes).unwrap())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here (edit: and a couple more spots in the code)
deku-derive/src/macros/deku_read.rs
Outdated
@@ -121,9 +131,19 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> { | |||
use ::#crate_::DekuReader as _; | |||
let mut __deku_cursor = #crate_::no_std_io::Cursor::new(__deku_input.0); | |||
let mut __deku_reader = &mut deku::reader::Reader::new(&mut __deku_cursor); | |||
if __deku_input.1 != 0 { | |||
__deku_reader.skip_bits(__deku_input.1)?; | |||
let bytes = __deku_input.1 / 8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this section is being repeated, worth having an emit_..
function for this new chunk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that also, it's weird to codegen this code over and over again instead of something in the reader
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, I forgot skip_bits was already only used for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ty!
* For bits input into from_bytes, first seek the byte amount until we can seek the bits amount Closes #500
ec07517
to
a8f31d1
Compare
Benchmark for ba10dc8Click to view benchmark
|
Benchmark for 6d8d88aClick to view benchmark
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Closes #500