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

Unified · Split

6 files
  1. etc/utils/src/command/release.rs +1 −5
  2. git-odb/src/store/loose/iter.rs +1 −5
  3. git-pack/src/data/input/bytes_to_entries.rs +3 −5
  4. git-pack/src/data/input/lookup_ref_delta_objects.rs +1 −5
  5. git-pack/src/data/output/count/iter_from_objects.rs +1 −5
  6. git-tempfile/src/fs/remove_dir.rs +1 −7
etc/utils/src/command/release.rs+1−5
@@ -137,11 +137,7 @@ fn find_directory_id_in_tree( · 136 unmodified lines
137 tree_id = tree_iter137 tree_id = tree_iter
138 .find_map(|e| {138 .find_map(|e| {
139 let e = e.expect("tree parseable");139 let e = e.expect("tree parseable");
140 if e.filename == c {140 (e.filename == c).then(|| e.oid)
141 Some(e.oid)
142 } else {
143 None
144 }
145 })141 })
146 .map(ToOwned::to_owned);142 .map(ToOwned::to_owned);
147 if tree_id.is_none() {143 if tree_id.is_none() {
git-odb/src/store/loose/iter.rs+1−5
@@ -45,11 +45,7 @@ impl Store { · 44 unmodified lines
45 }45 }
46 git_hash::ObjectId::null_sha1()46 git_hash::ObjectId::null_sha1()
47 });47 });
48 if is_valid_path {48 is_valid_path.then(|| e)
49 Some(e)
50 } else {
51 None
52 }
53 }49 }
54 50
55 /// Return an iterator over all objects contained in the database.51 /// Return an iterator over all objects contained in the database.
git-pack/src/data/input/bytes_to_entries.rs+3−5
@@ -61,13 +61,11 @@ where · 60 unmodified lines
61 had_error: false,61 had_error: false,
62 kind,62 kind,
63 objects_left: num_objects,63 objects_left: num_objects,
64 hash: if mode != input::Mode::AsIs {64 hash: (mode != input::Mode::AsIs).then(|| {
65 let mut hash = Sha1::default();65 let mut hash = Sha1::default();
66 hash.update(&header_data);66 hash.update(&header_data);
67 Some(hash)67 hash
68 } else {68 }),
69 None
70 },
71 mode,69 mode,
72 compressed_buf: None,70 compressed_buf: None,
73 })71 })
git-pack/src/data/input/lookup_ref_delta_objects.rs+1−5
@@ -149,11 +149,7 @@ where · 148 unmodified lines
149 self.inserted_entry_length_at_offset149 self.inserted_entry_length_at_offset
150 .get(maybe_index_of_actual_entry)150 .get(maybe_index_of_actual_entry)
151 .and_then(|c| {151 .and_then(|c| {
152 if c.pack_offset == base_pack_offset {152 (c.pack_offset == base_pack_offset).then(|| maybe_index_of_actual_entry)
153 Some(maybe_index_of_actual_entry)
154 } else {
155 None
156 }
157 })153 })
158 .unwrap_or(index)154 .unwrap_or(index)
159 };155 };
git-pack/src/data/output/count/iter_from_objects.rs+1−5
@@ -411,11 +411,7 @@ mod util { · 410 unmodified lines
411 break;411 break;
412 }412 }
413 }413 }
414 if res.is_empty() {414 (!res.is_empty()).then(|| res)
415 None
416 } else {
417 Some(res)
418 }
419 }415 }
420 }416 }
421}417}
git-tempfile/src/fs/remove_dir.rs+1−7
@@ -52,13 +52,7 @@ impl<'a> Iterator for Iter<'a> { · 51 unmodified lines
52 },52 },
53 };53 };
54 self.cursor = match dir.parent() {54 self.cursor = match dir.parent() {
55 Some(parent) => {55 Some(parent) => (parent != self.boundary).then(||parent),
56 if parent == self.boundary {
57 None
58 } else {
59 Some(parent)
60 }
61 },
62 None => unreachable!("directory {:?} ran out of parents, this really shouldn't happen before hitting the boundary {:?}"),56 None => unreachable!("directory {:?} ran out of parents, this really shouldn't happen before hitting the boundary {:?}"),
63 };57 };
64 next58 next