mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Simplify column look-up in default
(#13522)
# Description Since we make the promise that record keys/columns are exclusice we don't have to go through all columns after we have found the first one. Should permit some short-circuiting if the column is found early. # User-Facing Changes (-) # Tests + Formatting (-)
This commit is contained in:
parent
af34d5c062
commit
ff1ad77130
1 changed files with 6 additions and 12 deletions
|
@ -102,19 +102,13 @@ fn default(
|
|||
val: ref mut record,
|
||||
..
|
||||
} => {
|
||||
let mut found = false;
|
||||
|
||||
for (col, val) in record.to_mut().iter_mut() {
|
||||
if *col == column.item {
|
||||
found = true;
|
||||
if matches!(val, Value::Nothing { .. }) {
|
||||
*val = value.clone();
|
||||
}
|
||||
let record = record.to_mut();
|
||||
if let Some(val) = record.get_mut(&column.item) {
|
||||
if matches!(val, Value::Nothing { .. }) {
|
||||
*val = value.clone();
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
record.to_mut().push(column.item.clone(), value.clone());
|
||||
} else {
|
||||
record.push(column.item.clone(), value.clone());
|
||||
}
|
||||
|
||||
item
|
||||
|
|
Loading…
Reference in a new issue