1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 09:54:09 +01:00

Simplify group_locations_by_file

This commit is contained in:
Roman Zeyde 2020-11-15 20:00:00 +02:00
parent 2e7c249800
commit ca09e30b03
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB

View File

@ -534,16 +534,13 @@ fn load_locations(
}
fn group_locations_by_file(locations: Vec<BlockLocation>) -> BTreeMap<usize, Vec<BlockLocation>> {
let mut locations_by_file = BTreeMap::new();
for loc in locations.into_iter() {
locations_by_file
.entry(loc.file)
.or_insert_with(Vec::new)
.push(loc);
}
for locations in &mut locations_by_file.values_mut() {
locations.sort_by_key(|loc| loc.data);
}
let mut locations_by_file = BTreeMap::<usize, Vec<BlockLocation>>::new();
locations
.into_iter()
.for_each(|loc| locations_by_file.entry(loc.file).or_default().push(loc));
locations_by_file
.values_mut()
.for_each(|locations| locations.sort_by_key(|loc| loc.data));
locations_by_file
}