History

avoid unnecessary allocation when creating SHA1 paths in loose ODB

Sebastian Thiel committed 6 years ago

Commit 09d8d3a1 parent 4ff21684 files · +25 −31Browse files

Showing the changes to git-odb/src (1 of 4 files). Show all

Unified · Split

git-odb/src/loose/object.rs+3−16
@@ -3,7 +3,6 @@ use crate::{ · 2 unmodified lines
33 zlib,
44 };
55 use git_object as object;
6−use hex::ToHex;
76 use object::borrowed;
87 use quick_error::quick_error;
98 use smallvec::SmallVec;
@@ -128,21 +127,9 @@ pub fn parse_header(input: &[u8]) -> Result<(object::Kind, usize, usize), Error> · 118 unmodified lines
128127 }
129128
130129 fn sha1_path(id: &[u8; 20], mut root: PathBuf) -> PathBuf {
131− struct Buf([u8; 40], usize);
132− let mut buf = Buf([0u8; 40], 0);
133−
134− impl std::fmt::Write for Buf {
135− fn write_str(&mut self, s: &str) -> std::fmt::Result {
136− self.0[self.1..self.1 + buf.len()].copy_from_slice(buf);
137− self.1 += buf.len();
138− Ok(())
139− }
140− }
141−
142− {
143− id.write_hex(&mut buf)
144− .expect("no failure as everything is preset by now");
145− }
130+ let mut buf = [0u8; 40];
131+ hex::encode_to_slice(id, &mut buf).expect("no failure as everything is preset by now");
132+ let buf = std::str::from_utf8(&buf).expect("ascii only in hex");
146133 root.push(&buf[..2]);
147134 root.push(&buf[2..]);
148135 root

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t