mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
Make Value::columns
return slice instead of cloned Vec (#9927)
# Description This PR changes `Value::columns` to return a slice of columns instead of cloning said columns. If the caller needs an owned copy, they can use `slice::to_vec` or the like. This eliminates unnecessary Vec clones (e.g., in `update cells`). # User-Facing Changes Breaking change for `nu_protocol` API.
This commit is contained in:
parent
d302d63030
commit
c070e2d6f7
2 changed files with 4 additions and 4 deletions
|
@ -261,7 +261,7 @@ fn convert_to_list(
|
||||||
let mut iter = iter.into_iter().peekable();
|
let mut iter = iter.into_iter().peekable();
|
||||||
|
|
||||||
if let Some(first) = iter.peek() {
|
if let Some(first) = iter.peek() {
|
||||||
let mut headers = first.columns();
|
let mut headers = first.columns().to_vec();
|
||||||
|
|
||||||
if !headers.is_empty() {
|
if !headers.is_empty() {
|
||||||
headers.insert(0, "#".into());
|
headers.insert(0, "#".into());
|
||||||
|
|
|
@ -1732,10 +1732,10 @@ impl Value {
|
||||||
matches!(self, Value::Bool { val: false, .. })
|
matches!(self, Value::Bool { val: false, .. })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn columns(&self) -> Vec<String> {
|
pub fn columns(&self) -> &[String] {
|
||||||
match self {
|
match self {
|
||||||
Value::Record { cols, .. } => cols.clone(),
|
Value::Record { cols, .. } => cols,
|
||||||
_ => vec![],
|
_ => &[],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue