Skip to content

Commit

Permalink
fix!: use dyn trait where possible.
Browse files Browse the repository at this point in the history
This reduces compile time due to avoiding duplication.
  • Loading branch information
Byron committed Sep 4, 2023
1 parent eb8ed39 commit 50b7360
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gix-hash/src/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl oid {

/// Write ourselves to `out` in hexadecimal notation.
#[inline]
pub fn write_hex_to(&self, mut out: impl std::io::Write) -> std::io::Result<()> {
pub fn write_hex_to(&self, out: &mut dyn std::io::Write) -> std::io::Result<()> {
let mut hex = crate::Kind::hex_buf();
let hex_len = self.hex_to_buf(&mut hex);
out.write_all(&hex[..hex_len])
Expand Down
2 changes: 1 addition & 1 deletion gix-hash/src/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Prefix {
///
/// For instance, with `hex_len` of 7 the resulting prefix is 3.5 bytes, or 3 bytes and 4 bits
/// wide, with all other bytes and bits set to zero.
pub fn new(id: impl AsRef<oid>, hex_len: usize) -> Result<Self, Error> {
pub fn new(id: &oid, hex_len: usize) -> Result<Self, Error> {
let id = id.as_ref();
if hex_len > id.kind().len_in_hex() {
Err(Error::TooLong {
Expand Down
10 changes: 5 additions & 5 deletions gix-hash/tests/prefix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod cmp_oid {

#[test]
fn it_detects_inequality() {
let prefix = gix_hash::Prefix::new(hex_to_id("b920bbb055e1efb9080592a409d3975738b6efb3"), 7).unwrap();
let prefix = gix_hash::Prefix::new(&hex_to_id("b920bbb055e1efb9080592a409d3975738b6efb3"), 7).unwrap();
assert_eq!(
prefix.cmp_oid(&hex_to_id("a920bbb055e1efb9080592a409d3975738b6efb3")),
Ordering::Greater
Expand All @@ -20,7 +20,7 @@ mod cmp_oid {
#[test]
fn it_detects_equality() {
let id = hex_to_id("a920bbb055e1efb9080592a409d3975738b6efb3");
let prefix = gix_hash::Prefix::new(id, 6).unwrap();
let prefix = gix_hash::Prefix::new(&id, 6).unwrap();
assert_eq!(prefix.cmp_oid(&id), Ordering::Equal);
assert_eq!(
prefix.cmp_oid(&hex_to_id("a920bbffffffffffffffffffffffffffffffffff")),
Expand All @@ -46,7 +46,7 @@ mod new {
let mut expected = String::from(&oid_hex[..hex_len]);
let num_of_zeros = oid.kind().len_in_hex() - hex_len;
expected.extend(std::iter::repeat('0').take(num_of_zeros));
let prefix = gix_hash::Prefix::new(oid, hex_len).unwrap();
let prefix = gix_hash::Prefix::new(&oid, hex_len).unwrap();
assert_eq!(prefix.as_oid().to_hex().to_string(), expected, "{hex_len}");
assert_eq!(prefix.hex_len(), hex_len);
assert_eq!(prefix.cmp_oid(&oid), Ordering::Equal);
Expand All @@ -57,7 +57,7 @@ mod new {
fn errors_if_hex_len_is_longer_than_oid_len_in_hex() {
let kind = Kind::Sha1;
assert!(matches!(
gix_hash::Prefix::new(ObjectId::null(kind), kind.len_in_hex() + 1),
gix_hash::Prefix::new(&ObjectId::null(kind), kind.len_in_hex() + 1),
Err(gix_hash::prefix::Error::TooLong { .. })
));
}
Expand All @@ -66,7 +66,7 @@ mod new {
fn errors_if_hex_len_is_too_short() {
let kind = Kind::Sha1;
assert!(matches!(
gix_hash::Prefix::new(ObjectId::null(kind), 3),
gix_hash::Prefix::new(&ObjectId::null(kind), 3),
Err(gix_hash::prefix::Error::TooShort { .. })
));
}
Expand Down

0 comments on commit 50b7360

Please sign in to comment.