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:
Devyn Cairns
2024-07-10 19:14:05 -07:00
committed by GitHub
parent f87cf895c2
commit 801cfae279
2 changed files with 6 additions and 7 deletions

View File

@ -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()
}
}