Skip to content

Commit

Permalink
refactor: template lookup_filter to eliminate unnecessary cloning
Browse files Browse the repository at this point in the history
by moving the entire lookup logic inside closure to avoid returning references
  • Loading branch information
jqnatividad committed Nov 27, 2024
1 parent 12ce22b commit 50be4d5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/cmd/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,19 +786,19 @@ fn lookup_filter(
Ok(LOOKUP_MAP
.get()
.and_then(|lock| lock.read().ok())
.and_then(|map| map.get(lookup_name).cloned())
.and_then(|table| {
.and_then(|map| {
let table = map.get(lookup_name)?;
// Find the matching row
if case_sensitive {
table.get(value).and_then(|row| row.get(field).cloned())
table.get(value).and_then(|row| row.get(field).map(String::from))
} else {
table
.iter()
.find(|(k, _)| {
util::to_lowercase_into(k, &mut lowercase_buffer);
lowercase_buffer == value_compare
})
.and_then(|(_, row)| row.get(field).cloned())
.and_then(|(_, row)| row.get(field).map(String::from))
}
})
.unwrap_or_else(|| {
Expand Down

0 comments on commit 50be4d5

Please sign in to comment.