Skip to content

Commit

Permalink
chore: use faster-hex instead of hex
Browse files Browse the repository at this point in the history
The performance here certainly doesn't make a difference, but we
try to avoid duplicate dependencies.
  • Loading branch information
Byron committed Aug 16, 2023
1 parent dbe5cba commit 9ef69e1
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gix-packetline-blocking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ serde = ["dep:serde", "bstr/serde"]
[dependencies]
serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"]}
thiserror = "1.0.34"
hex = "0.4.2"
faster-hex = "0.8.0"
bstr = { version = "1.3.0", default-features = false, features = ["std"] }

document-features = { version = "0.2.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion gix-packetline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ required-features = ["blocking-io", "maybe-async/is_sync"]
[dependencies]
serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"]}
thiserror = "1.0.34"
hex = "0.4.2"
faster-hex = "0.8.0"
bstr = { version = "1.3.0", default-features = false, features = ["std"] }
# async support
futures-io = { version = "0.3.16", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion gix-packetline/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn hex_prefix(four_bytes: &[u8]) -> Result<PacketLineOrWantedSize<'_>, Error
}

let mut buf = [0u8; U16_HEX_BYTES / 2];
hex::decode_to_slice(four_bytes, &mut buf).map_err(|err| Error::HexDecode { err: err.to_string() })?;
faster_hex::hex_decode(four_bytes, &mut buf).map_err(|err| Error::HexDecode { err: err.to_string() })?;
let wanted_bytes = u16::from_be_bytes(buf);

if wanted_bytes == 3 {
Expand Down
2 changes: 1 addition & 1 deletion gix-packetline/src/encode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ pub use blocking_io::*;

pub(crate) fn u16_to_hex(value: u16) -> [u8; 4] {
let mut buf = [0u8; 4];
hex::encode_to_slice(value.to_be_bytes(), &mut buf).expect("two bytes to 4 hex chars never fails");
faster_hex::hex_encode(&value.to_be_bytes(), &mut buf).expect("two bytes to 4 hex chars never fails");
buf
}
2 changes: 1 addition & 1 deletion gix-packetline/tests/decode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ mod streaming {
fn error_on_invalid_hex() {
assert_err_display(
streaming(b"fooo"),
"Failed to decode the first four hex bytes indicating the line length: Invalid character 'o' at position 1",
"Failed to decode the first four hex bytes indicating the line length: Invalid character",
);
}

Expand Down
61 changes: 35 additions & 26 deletions gix-revision/fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9ef69e1

Please sign in to comment.