Remove conversions & shorten variable lifetime

This commit is contained in:
2020-01-07 10:16:39 +01:00
parent b384fc4c7e
commit fdade86b2a
3 changed files with 12 additions and 19 deletions

View File

@@ -53,7 +53,7 @@ impl SpaceFields {
pub fn new(space_id: &str, value: usize) -> Self {
SpaceFields {
space_id: space_id.into(),
value: value.into(),
value,
}
}

View File

@@ -169,9 +169,8 @@ pub fn build_index(
let mut properties = vec![];
let mut space_set_objects = vec![];
let mut properties_ref = vec![];
{
let mut properties_ref = vec![];
let mut properties_hm = HashMap::new();
for object in objects {
@@ -204,16 +203,15 @@ pub fn build_index(
}
properties.append(&mut properties_hm.drain().map(|(_, v)| v).collect::<Vec<_>>());
properties.sort_unstable_by(|a, b| a.id().cmp(b.id()));
space_set_objects.iter_mut().for_each(|object| {
let id = properties_ref[object.value()];
let value = properties.binary_search_by_key(&id, |p| p.id()).unwrap();
object.set_value(value);
});
}
properties.sort_unstable_by(|a, b| a.id().cmp(b.id()));
space_set_objects.iter_mut().for_each(|object| {
let id = properties_ref[object.value()];
let value = properties.binary_search_by_key(&id, |p| p.id()).unwrap();
object.set_value(value);
});
Core::new(
name,
version,

View File

@@ -86,14 +86,9 @@ pub fn build(
.map(|s| s.into())
.collect::<Vec<_>>();
let core = model::build_index(
name,
version,
&spaces,
&load::<Vec<model::SpatialObject>>(&fn_objects),
scales,
max_elements,
);
let objects = load::<Vec<model::SpatialObject>>(&fn_objects);
let core = model::build_index(name, version, &spaces, &objects, scales, max_elements);
store((spaces, core), &fn_index);
}