Skip to content

Commit 50b7360

Browse files
committed
fix!: use dyn trait where possible.
This reduces compile time due to avoiding duplication.
1 parent eb8ed39 commit 50b7360

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

gix-hash/src/oid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl oid {
154154

155155
/// Write ourselves to `out` in hexadecimal notation.
156156
#[inline]
157-
pub fn write_hex_to(&self, mut out: impl std::io::Write) -> std::io::Result<()> {
157+
pub fn write_hex_to(&self, out: &mut dyn std::io::Write) -> std::io::Result<()> {
158158
let mut hex = crate::Kind::hex_buf();
159159
let hex_len = self.hex_to_buf(&mut hex);
160160
out.write_all(&hex[..hex_len])

gix-hash/src/prefix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Prefix {
4141
///
4242
/// For instance, with `hex_len` of 7 the resulting prefix is 3.5 bytes, or 3 bytes and 4 bits
4343
/// wide, with all other bytes and bits set to zero.
44-
pub fn new(id: impl AsRef<oid>, hex_len: usize) -> Result<Self, Error> {
44+
pub fn new(id: &oid, hex_len: usize) -> Result<Self, Error> {
4545
let id = id.as_ref();
4646
if hex_len > id.kind().len_in_hex() {
4747
Err(Error::TooLong {

gix-hash/tests/prefix/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod cmp_oid {
55

66
#[test]
77
fn it_detects_inequality() {
8-
let prefix = gix_hash::Prefix::new(hex_to_id("b920bbb055e1efb9080592a409d3975738b6efb3"), 7).unwrap();
8+
let prefix = gix_hash::Prefix::new(&hex_to_id("b920bbb055e1efb9080592a409d3975738b6efb3"), 7).unwrap();
99
assert_eq!(
1010
prefix.cmp_oid(&hex_to_id("a920bbb055e1efb9080592a409d3975738b6efb3")),
1111
Ordering::Greater
@@ -20,7 +20,7 @@ mod cmp_oid {
2020
#[test]
2121
fn it_detects_equality() {
2222
let id = hex_to_id("a920bbb055e1efb9080592a409d3975738b6efb3");
23-
let prefix = gix_hash::Prefix::new(id, 6).unwrap();
23+
let prefix = gix_hash::Prefix::new(&id, 6).unwrap();
2424
assert_eq!(prefix.cmp_oid(&id), Ordering::Equal);
2525
assert_eq!(
2626
prefix.cmp_oid(&hex_to_id("a920bbffffffffffffffffffffffffffffffffff")),
@@ -46,7 +46,7 @@ mod new {
4646
let mut expected = String::from(&oid_hex[..hex_len]);
4747
let num_of_zeros = oid.kind().len_in_hex() - hex_len;
4848
expected.extend(std::iter::repeat('0').take(num_of_zeros));
49-
let prefix = gix_hash::Prefix::new(oid, hex_len).unwrap();
49+
let prefix = gix_hash::Prefix::new(&oid, hex_len).unwrap();
5050
assert_eq!(prefix.as_oid().to_hex().to_string(), expected, "{hex_len}");
5151
assert_eq!(prefix.hex_len(), hex_len);
5252
assert_eq!(prefix.cmp_oid(&oid), Ordering::Equal);
@@ -57,7 +57,7 @@ mod new {
5757
fn errors_if_hex_len_is_longer_than_oid_len_in_hex() {
5858
let kind = Kind::Sha1;
5959
assert!(matches!(
60-
gix_hash::Prefix::new(ObjectId::null(kind), kind.len_in_hex() + 1),
60+
gix_hash::Prefix::new(&ObjectId::null(kind), kind.len_in_hex() + 1),
6161
Err(gix_hash::prefix::Error::TooLong { .. })
6262
));
6363
}
@@ -66,7 +66,7 @@ mod new {
6666
fn errors_if_hex_len_is_too_short() {
6767
let kind = Kind::Sha1;
6868
assert!(matches!(
69-
gix_hash::Prefix::new(ObjectId::null(kind), 3),
69+
gix_hash::Prefix::new(&ObjectId::null(kind), 3),
7070
Err(gix_hash::prefix::Error::TooShort { .. })
7171
));
7272
}

0 commit comments

Comments
 (0)