History

[commitgraph] Tweak `File::iter_base_graph_ids` implementation.

* It doesn't use evil `as`. * It's a bit less code. * It should be a tiny bit faster. * It is slightly more strict in that it will panic if the base graphs list is not evenly divisible into hashes. The file parser's error checking should ensure that this panic never happens, but maybe maybe maybe...

Conor Davis committed 6 years ago

Commit 5b067801 parent a7830521 file · +3 −5Browse files

Showing the changes to git-commitgraph/src (1 of 1 file). Show all

Unified · Split

git-commitgraph/src/file/access.rs+3−5
@@ -42,12 +42,10 @@ impl File { · 41 unmodified lines
42 }42 }
43 43
44 pub fn iter_base_graph_ids(&self) -> impl Iterator<Item = borrowed::Id<'_>> {44 pub fn iter_base_graph_ids(&self) -> impl Iterator<Item = borrowed::Id<'_>> {
45 let base_graphs_list = match self.base_graphs_list_offset {45 let start = self.base_graphs_list_offset.unwrap_or(0);
46 Some(v) => &self.data[v..v + (SHA1_SIZE * self.base_graph_count as usize)],46 let base_graphs_list = &self.data[start..start + (SHA1_SIZE * usize::from(self.base_graph_count))];
47 None => &[],
48 };
49 base_graphs_list47 base_graphs_list
50 .chunks_exact(SHA1_SIZE)48 .chunks(SHA1_SIZE)
51 .map(|bytes| borrowed::Id::try_from(bytes).expect("20 bytes SHA1 to be alright"))49 .map(|bytes| borrowed::Id::try_from(bytes).expect("20 bytes SHA1 to be alright"))
52 }50 }
53 51

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