Skip to content

Commit

Permalink
chore: replace bunch of get(x).is_some() by contains(x)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Tardy <[email protected]>
  • Loading branch information
tardyp authored and DanielT committed Nov 15, 2023
1 parent b5e0fd9 commit dcf3167
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/cleanup/compu_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn remove_unused_compumethods(module: &mut Module) {

module
.compu_method
.retain(|item| used_compumethods.get(&item.name).is_some());
.retain(|item| used_compumethods.contains(&item.name));
}

fn remove_unused_sub_elements(module: &mut Module) {
Expand All @@ -117,13 +117,13 @@ fn remove_unused_sub_elements(module: &mut Module) {

module
.compu_tab
.retain(|item| used_compu_tabs.get(&item.name).is_some());
.retain(|item| used_compu_tabs.contains(&item.name));
module
.compu_vtab
.retain(|item| used_compu_tabs.get(&item.name).is_some());
.retain(|item| used_compu_tabs.contains(&item.name));
module
.compu_vtab_range
.retain(|item| used_compu_tabs.get(&item.name).is_some());
.retain(|item| used_compu_tabs.contains(&item.name));

// remove all unused UNITs
for unit in &module.unit {
Expand All @@ -134,7 +134,7 @@ fn remove_unused_sub_elements(module: &mut Module) {

module
.unit
.retain(|item| used_units.get(&item.name).is_some());
.retain(|item| used_units.contains(&item.name));
}

fn remove_invalid_sub_element_refs(module: &mut Module) {
Expand Down
20 changes: 10 additions & 10 deletions src/cleanup/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,39 +146,39 @@ fn remove_broken_func_refs(module: &mut Module) {
if let Some(function_list) = &mut axispts.function_list {
function_list
.name_list
.retain(|name| existing_functions.get(name).is_some());
.retain(|name| existing_functions.contains(name));
}
}

for chara in &mut module.characteristic {
if let Some(function_list) = &mut chara.function_list {
function_list
.name_list
.retain(|name| existing_functions.get(name).is_some());
.retain(|name| existing_functions.contains(name));
}
}

for meas in &mut module.measurement {
if let Some(function_list) = &mut meas.function_list {
function_list
.name_list
.retain(|name| existing_functions.get(name).is_some());
.retain(|name| existing_functions.contains(name));
}
}

for group in &mut module.group {
if let Some(function_list) = &mut group.function_list {
function_list
.name_list
.retain(|name| existing_functions.get(name).is_some());
.retain(|name| existing_functions.contains(name));
}
}

for function in &mut module.function {
if let Some(sub_functions) = &mut function.sub_function {
sub_functions
.identifier_list
.retain(|name| existing_functions.get(name).is_some());
.retain(|name| existing_functions.contains(name));
}
}
}
Expand Down Expand Up @@ -210,27 +210,27 @@ fn remove_broken_object_refs(module: &mut Module) {
if let Some(ref_characteristic) = &mut func.ref_characteristic {
ref_characteristic
.identifier_list
.retain(|ident| object_names.get(ident).is_some());
.retain(|ident| object_names.contains(ident));
}
if let Some(def_characteristic) = &mut func.def_characteristic {
def_characteristic
.identifier_list
.retain(|ident| object_names.get(ident).is_some());
.retain(|ident| object_names.contains(ident));
}
if let Some(in_measurement) = &mut func.in_measurement {
in_measurement
.identifier_list
.retain(|ident| object_names.get(ident).is_some());
.retain(|ident| object_names.contains(ident));
}
if let Some(loc_measurement) = &mut func.loc_measurement {
loc_measurement
.identifier_list
.retain(|ident| object_names.get(ident).is_some());
.retain(|ident| object_names.contains(ident));
}
if let Some(out_measurement) = &mut func.out_measurement {
out_measurement
.identifier_list
.retain(|ident| object_names.get(ident).is_some());
.retain(|ident| object_names.contains(ident));
}
}
}
4 changes: 2 additions & 2 deletions src/cleanup/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn remove_invalid_object_references(module: &mut Module) {
// retain only references to existing characteristics
ref_characteristic
.identifier_list
.retain(|item| refnames.get(item).is_some());
.retain(|item| refnames.contains(item));
if ref_characteristic.identifier_list.is_empty() {
grp.ref_characteristic = None;
}
Expand All @@ -29,7 +29,7 @@ fn remove_invalid_object_references(module: &mut Module) {
// retain only references to existing measurements
ref_measurement
.identifier_list
.retain(|item| refnames.get(item).is_some());
.retain(|item| refnames.contains(item));
if ref_measurement.identifier_list.is_empty() {
grp.ref_measurement = None;
}
Expand Down
3 changes: 1 addition & 2 deletions src/cleanup/record_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ pub(crate) fn cleanup(module: &mut Module) {
used_record_layouts.insert(s_rec_layout.name.to_owned());
}
}

// remove all unused RECORD_LAYOUTs
module
.record_layout
.retain(|item| used_record_layouts.get(&item.name).is_some());
.retain(|item| used_record_layouts.contains(&item.name));
}

0 comments on commit dcf3167

Please sign in to comment.