mirror of
https://github.com/nushell/nushell.git
synced 2024-11-24 17:34:00 +01: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
@ -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 New Issue
Block a user