summaryrefslogtreecommitdiffstats
path: root/vendor/gix-hash/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/gix-hash/src
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-hash/src')
-rw-r--r--vendor/gix-hash/src/object_id.rs25
-rw-r--r--vendor/gix-hash/src/oid.rs4
-rw-r--r--vendor/gix-hash/src/prefix.rs20
3 files changed, 27 insertions, 22 deletions
diff --git a/vendor/gix-hash/src/object_id.rs b/vendor/gix-hash/src/object_id.rs
index 8bf19a744..fe1b2e9ba 100644
--- a/vendor/gix-hash/src/object_id.rs
+++ b/vendor/gix-hash/src/object_id.rs
@@ -40,8 +40,8 @@ pub mod decode {
pub enum Error {
#[error("A hash sized {0} hexadecimal characters is invalid")]
InvalidHexEncodingLength(usize),
- #[error("Invalid character {c} at position {index}")]
- Invalid { c: char, index: usize },
+ #[error("Invalid character encountered")]
+ Invalid,
}
/// Hash decoding
@@ -50,16 +50,19 @@ pub mod decode {
///
/// Such a buffer can be obtained using [`oid::write_hex_to(buffer)`][super::oid::write_hex_to()]
pub fn from_hex(buffer: &[u8]) -> Result<ObjectId, Error> {
- use hex::FromHex;
match buffer.len() {
- 40 => Ok(ObjectId::Sha1(<[u8; 20]>::from_hex(buffer).map_err(
- |err| match err {
- hex::FromHexError::InvalidHexCharacter { c, index } => Error::Invalid { c, index },
- hex::FromHexError::OddLength | hex::FromHexError::InvalidStringLength => {
- unreachable!("BUG: This is already checked")
- }
- },
- )?)),
+ 40 => Ok({
+ ObjectId::Sha1({
+ let mut buf = [0; 20];
+ faster_hex::hex_decode(buffer, &mut buf).map_err(|err| match err {
+ faster_hex::Error::InvalidChar => Error::Invalid,
+ faster_hex::Error::InvalidLength(_) => {
+ unreachable!("BUG: This is already checked")
+ }
+ })?;
+ buf
+ })
+ }),
len => Err(Error::InvalidHexEncodingLength(len)),
}
}
diff --git a/vendor/gix-hash/src/oid.rs b/vendor/gix-hash/src/oid.rs
index 45380caff..b105621cb 100644
--- a/vendor/gix-hash/src/oid.rs
+++ b/vendor/gix-hash/src/oid.rs
@@ -148,13 +148,13 @@ impl oid {
#[must_use]
pub fn hex_to_buf(&self, buf: &mut [u8]) -> usize {
let num_hex_bytes = self.bytes.len() * 2;
- hex::encode_to_slice(&self.bytes, &mut buf[..num_hex_bytes]).expect("to count correctly");
+ faster_hex::hex_encode(&self.bytes, &mut buf[..num_hex_bytes]).expect("to count correctly");
num_hex_bytes
}
/// 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])
diff --git a/vendor/gix-hash/src/prefix.rs b/vendor/gix-hash/src/prefix.rs
index 166b3c3e7..c8e1b1847 100644
--- a/vendor/gix-hash/src/prefix.rs
+++ b/vendor/gix-hash/src/prefix.rs
@@ -28,8 +28,8 @@ pub mod from_hex {
TooShort { hex_len: usize },
#[error("An id cannot be larger than {} chars in hex, but {hex_len} was requested", crate::Kind::longest().len_in_hex())]
TooLong { hex_len: usize },
- #[error("Invalid character {c} at position {index}")]
- Invalid { c: char, index: usize },
+ #[error("Invalid hex character")]
+ Invalid,
}
}
@@ -41,8 +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> {
- let id = id.as_ref();
+ pub fn new(id: &oid, hex_len: usize) -> Result<Self, Error> {
if hex_len > id.kind().len_in_hex() {
Err(Error::TooLong {
object_kind: id.kind(),
@@ -95,7 +94,6 @@ impl Prefix {
/// Create an instance from the given hexadecimal prefix `value`, e.g. `35e77c16` would yield a `Prefix` with `hex_len()` = 8.
pub fn from_hex(value: &str) -> Result<Self, from_hex::Error> {
- use hex::FromHex;
let hex_len = value.len();
if hex_len > crate::Kind::longest().len_in_hex() {
@@ -105,16 +103,20 @@ impl Prefix {
};
let src = if value.len() % 2 == 0 {
- Vec::from_hex(value)
+ let mut out = Vec::from_iter(std::iter::repeat(0).take(value.len() / 2));
+ faster_hex::hex_decode(value.as_bytes(), &mut out).map(move |_| out)
} else {
+ // TODO(perf): do without heap allocation here.
let mut buf = [0u8; crate::Kind::longest().len_in_hex()];
buf[..value.len()].copy_from_slice(value.as_bytes());
buf[value.len()] = b'0';
- Vec::from_hex(&buf[..=value.len()])
+ let src = &buf[..=value.len()];
+ let mut out = Vec::from_iter(std::iter::repeat(0).take(src.len() / 2));
+ faster_hex::hex_decode(src, &mut out).map(move |_| out)
}
.map_err(|e| match e {
- hex::FromHexError::InvalidHexCharacter { c, index } => from_hex::Error::Invalid { c, index },
- hex::FromHexError::OddLength | hex::FromHexError::InvalidStringLength => panic!("This is already checked"),
+ faster_hex::Error::InvalidChar => from_hex::Error::Invalid,
+ faster_hex::Error::InvalidLength(_) => panic!("This is already checked"),
})?;
let mut bytes = ObjectId::null(crate::Kind::from_hex_len(value.len()).expect("hex-len is already checked"));