From e62356f5ecd152748ea603981000f496a398f365 Mon Sep 17 00:00:00 2001 From: sholderbach Date: Fri, 2 Aug 2024 23:10:19 +0200 Subject: [PATCH] Simplify column look-up in `default` 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. --- crates/nu-command/src/filters/default.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/crates/nu-command/src/filters/default.rs b/crates/nu-command/src/filters/default.rs index 3f7f93c3f6..60c43fa88f 100644 --- a/crates/nu-command/src/filters/default.rs +++ b/crates/nu-command/src/filters/default.rs @@ -102,18 +102,11 @@ 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(); - } + if let Some(val) = record.to_mut().get_mut(&column.item) { + if matches!(val, Value::Nothing { .. }) { + *val = value.clone(); } - } - - if !found { + } else { record.to_mut().push(column.item.clone(), value.clone()); }