perf: better scalability of get_columns (#15780)

# Description

Use hashset for existence checking.
Still needs a vector collection to keep the column order for tables.

# User-Facing Changes

Should be None
This commit is contained in:
zc he
2025-06-20 18:07:23 +08:00
committed by GitHub
parent d9d022733f
commit 7ee8aa78cc

View File

@ -2,14 +2,15 @@ use nu_protocol::Value;
use std::collections::HashSet;
pub fn get_columns(input: &[Value]) -> Vec<String> {
let mut columns = vec![];
let mut column_set = HashSet::new();
let mut columns = Vec::new();
for item in input {
let Value::Record { val, .. } = item else {
return vec![];
};
for col in val.columns() {
if !columns.contains(col) {
if column_set.insert(col) {
columns.push(col.to_string());
}
}