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

Unified · Split

4 files
  1. Cargo.lock +20 −13
  2. git-object/Cargo.toml +1 −1
  3. git-odb/Cargo.toml +1 −1
  4. git-odb/src/loose/object.rs +3 −16
Cargo.lock+20−13
@@ -2,9 +2,9 @@ · 1 unmodified line
22 # It is not intended for manual editing.
33 [[package]]
44 name = "adler32"
5−version = "1.0.4"
5+version = "1.1.0"
66 source = "registry+https://github.com/rust-lang/crates.io-index"
7−checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2"
7+checksum = "567b077b825e468cc974f0020d4082ee6e03132512f207ef1a02fd5d00d1f32d"
88
99 [[package]]
1010 name = "ansi_term"
@@ -182,7 +182,7 @@ version = "0.1.0" · 171 unmodified lines
182182 dependencies = [
183183 "anyhow",
184184 "git-odb",
185− "hex",
185+ "hex 0.3.2",
186186 "rayon",
187187 ]
188188
@@ -192,7 +192,7 @@ version = "0.1.0" · 3 unmodified lines
192192 dependencies = [
193193 "bstr",
194194 "btoi",
195− "hex",
195+ "hex 0.4.2",
196196 "nom",
197197 "pretty_assertions",
198198 "quick-error",
@@ -207,7 +207,7 @@ dependencies = [ · 8 unmodified lines
207207 "byteorder",
208208 "filebuffer",
209209 "git-object",
210− "hex",
210+ "hex 0.4.2",
211211 "miniz_oxide",
212212 "pretty_assertions",
213213 "quick-error",
@@ -248,6 +248,12 @@ version = "0.3.2" · 34 unmodified lines
248248 source = "registry+https://github.com/rust-lang/crates.io-index"
249249 checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"
250250
251+[[package]]
252+name = "hex"
253+version = "0.4.2"
254+source = "registry+https://github.com/rust-lang/crates.io-index"
255+checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
256+
251257 [[package]]
252258 name = "lazy_static"
253259 version = "1.4.0"
@@ -392,10 +398,11 @@ dependencies = [ · 138 unmodified lines
392398
393399 [[package]]
394400 name = "rayon"
395−version = "1.3.0"
401+version = "1.3.1"
396402 source = "registry+https://github.com/rust-lang/crates.io-index"
397−checksum = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098"
403+checksum = "62f02856753d04e03e26929f820d0a0a337ebe71f849801eea335d464b349080"
398404 dependencies = [
405+ "autocfg",
399406 "crossbeam-deque",
400407 "either",
401408 "rayon-core",
@@ -403,9 +410,9 @@ dependencies = [ · 1 unmodified line
403410
404411 [[package]]
405412 name = "rayon-core"
406−version = "1.7.0"
413+version = "1.7.1"
407414 source = "registry+https://github.com/rust-lang/crates.io-index"
408−checksum = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9"
415+checksum = "e92e15d89083484e11353891f1af602cc661426deb9564c298b270c726973280"
409416 dependencies = [
410417 "crossbeam-deque",
411418 "crossbeam-queue",
@@ -443,9 +450,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" · 31 unmodified lines
443450
444451 [[package]]
445452 name = "structopt"
446−version = "0.3.14"
453+version = "0.3.15"
447454 source = "registry+https://github.com/rust-lang/crates.io-index"
448−checksum = "863246aaf5ddd0d6928dfeb1a9ca65f505599e4e1b399935ef7e75107516b4ef"
455+checksum = "de2f5e239ee807089b62adce73e48c625e0ed80df02c7ab3f068f5db5281065c"
449456 dependencies = [
450457 "clap",
451458 "lazy_static",
@@ -454,9 +461,9 @@ dependencies = [ · 2 unmodified lines
454461
455462 [[package]]
456463 name = "structopt-derive"
457−version = "0.4.7"
464+version = "0.4.8"
458465 source = "registry+https://github.com/rust-lang/crates.io-index"
459−checksum = "d239ca4b13aee7a2142e6795cbd69e457665ff8037aed33b3effdc430d2f927a"
466+checksum = "510413f9de616762a4fbeab62509bf15c729603b72d7cd71280fbca431b1c118"
460467 dependencies = [
461468 "heck",
462469 "proc-macro-error",
git-object/Cargo.toml+1−1
@@ -10,7 +10,7 @@ doctest = false · 9 unmodified lines
1010
1111 [dependencies]
1212 quick-error = "1.2.3"
13−hex = "0.3.2"
13+hex = "0.4.2"
1414 btoi = "0.4.2"
1515 bstr = { version = "0.2.13", default-features = false, features = ["std"] }
1616 nom = { version = "6.0.0-alpha1", default-features = false }
git-odb/Cargo.toml+1−1
@@ -11,7 +11,7 @@ doctest = false · 10 unmodified lines
1111 [dependencies]
1212 quick-error = "1.2.3"
1313 walkdir = "2.1.4"
14−hex = "0.3.2"
14+hex = "0.4.2"
1515 miniz_oxide = "0.3.6"
1616 smallvec = "1.3.0"
1717 filebuffer = "0.4.0"
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