mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 09:45:50 +02:00
Avoid clone in Signature::get_positional()
(#13338)
# Description `Signature::get_positional()` was returning an owned `PositionalArg`, which contains a bunch of strings. `ClosureEval` uses this in `try_add_arg`, making all of that unnecessary cloning a little bit hot. # User-Facing Changes Slightly better performance
This commit is contained in:
@ -485,15 +485,14 @@ impl Signature {
|
||||
(name, s)
|
||||
}
|
||||
|
||||
pub fn get_positional(&self, position: usize) -> Option<PositionalArg> {
|
||||
pub fn get_positional(&self, position: usize) -> Option<&PositionalArg> {
|
||||
if position < self.required_positional.len() {
|
||||
self.required_positional.get(position).cloned()
|
||||
self.required_positional.get(position)
|
||||
} else if position < (self.required_positional.len() + self.optional_positional.len()) {
|
||||
self.optional_positional
|
||||
.get(position - self.required_positional.len())
|
||||
.cloned()
|
||||
} else {
|
||||
self.rest_positional.clone()
|
||||
self.rest_positional.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user