History

[utils #154] refactor: bool.then(||this) - neat

Should keep practicing its usage so that this wonderful code multiplies.

Sebastian Thiel committed 5 years ago

Commit 1dec1c41 parent ae4fb9c6 files · +8 −32Browse files

Showing the changes to git-pack/src/data/input (2 of 6 files). Show all

Unified · Split

2 files
  1. git-pack/src/data/input/bytes_to_entries.rs +3 −5
  2. git-pack/src/data/input/lookup_ref_delta_objects.rs +1 −5
git-pack/src/data/input/bytes_to_entries.rs+3−5
@@ -61,13 +61,11 @@ where · 60 unmodified lines
6161 had_error: false,
6262 kind,
6363 objects_left: num_objects,
64− hash: if mode != input::Mode::AsIs {
64+ hash: (mode != input::Mode::AsIs).then(|| {
6565 let mut hash = Sha1::default();
6666 hash.update(&header_data);
67− Some(hash)
68− } else {
69− None
70− },
67+ hash
68+ }),
7169 mode,
7270 compressed_buf: None,
7371 })
git-pack/src/data/input/lookup_ref_delta_objects.rs+1−5
@@ -149,11 +149,7 @@ where · 148 unmodified lines
149149 self.inserted_entry_length_at_offset
150150 .get(maybe_index_of_actual_entry)
151151 .and_then(|c| {
152− if c.pack_offset == base_pack_offset {
153− Some(maybe_index_of_actual_entry)
154− } else {
155− None
156− }
152+ (c.pack_offset == base_pack_offset).then(|| maybe_index_of_actual_entry)
157153 })
158154 .unwrap_or(index)
159155 };

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