mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +02:00
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:
@ -2,14 +2,15 @@ use nu_protocol::Value;
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
pub fn get_columns(input: &[Value]) -> Vec<String> {
|
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 {
|
for item in input {
|
||||||
let Value::Record { val, .. } = item else {
|
let Value::Record { val, .. } = item else {
|
||||||
return vec![];
|
return vec![];
|
||||||
};
|
};
|
||||||
|
|
||||||
for col in val.columns() {
|
for col in val.columns() {
|
||||||
if !columns.contains(col) {
|
if column_set.insert(col) {
|
||||||
columns.push(col.to_string());
|
columns.push(col.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user