Skip to content
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

Remove byteorder, use bytes::Buf::get_uint instead #477

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nylonicious
Copy link

byteorder was only used in one place and since bytes crate implements similar functionality it lets us drop it pretty easily.

Copy link

@hkBst hkBst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing byteorder is good, since it does not add much that is not already in std, but using the bytes crate here is also unnecessary. If you go explore there you'll find it does:

let slice_at = match 8.checked_sub(length_length) {
    Some(slice_at) => slice_at,
    None => panic_does_not_fit(8, length_length),
};

let mut buf = [0; 8];
buffer[..length_length].as_ref().copy_to_slice(&mut buf[slice_at..]);
return u64::from_be_bytes(buf);

If we copy the bytes into our own 8-byte buffer but start at slice_at like the code above, then the copy is just not necessary.

@nylonicious
Copy link
Author

Thanks for pointing that out, hopefully I managed to get it right this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants