Remove allocation in Git SHA truncation (#10801)

This commit is contained in:
Charlie Marsh 2025-01-20 20:53:12 -05:00 committed by GitHub
parent 154fd6bd23
commit 44d2bfeb65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 6 deletions

View file

@ -8,9 +8,14 @@ use thiserror::Error;
pub struct GitSha(GitOid);
impl GitSha {
/// Convert the SHA to a truncated representation, i.e., the first 16 characters of the SHA.
pub fn to_short_string(&self) -> String {
self.0.to_string()[0..16].to_string()
/// Return the Git SHA as a string.
pub fn as_str(&self) -> &str {
self.0.as_str()
}
/// Return a truncated representation, i.e., the first 16 characters of the SHA.
pub fn as_short_str(&self) -> &str {
&self.0.as_str()[..16]
}
}