Skip to content

Commit 1c5575c

Browse files
committed
perf: better scalability of get_columns
1 parent 5483519 commit 1c5575c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

crates/nu-engine/src/column.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ use nu_protocol::Value;
22
use std::collections::HashSet;
33

44
pub fn get_columns(input: &[Value]) -> Vec<String> {
5-
let mut columns = vec![];
5+
let mut columns = HashSet::new();
66
for item in input {
77
let Value::Record { val, .. } = item else {
88
return vec![];
99
};
1010

1111
for col in val.columns() {
12-
if !columns.contains(col) {
13-
columns.push(col.to_string());
14-
}
12+
columns.insert(col.to_string());
1513
}
1614
}
1715

18-
columns
16+
columns.into_iter().collect()
1917
}
2018

2119
// If a column doesn't exist in the input, return it.

0 commit comments

Comments
 (0)