From ff1ad77130b4a5baa6bbc6728e99023340f8842a Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Sat, 3 Aug 2024 00:26:35 +0200 Subject: [PATCH] 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 (-) --- crates/nu-command/src/filters/default.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/crates/nu-command/src/filters/default.rs b/crates/nu-command/src/filters/default.rs index 3f7f93c3f6..e269c58ccd 100644 --- a/crates/nu-command/src/filters/default.rs +++ b/crates/nu-command/src/filters/default.rs @@ -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