Avoid clone in Signature::get_positional()
This commit is contained in:
parent
ea8c4e3af2
commit
f4278840f0
|
@ -486,15 +486,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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ fn test_signature_chained() {
|
|||
|
||||
assert_eq!(
|
||||
signature.get_positional(0),
|
||||
Some(PositionalArg {
|
||||
Some(&PositionalArg {
|
||||
name: "required".to_string(),
|
||||
desc: "required description".to_string(),
|
||||
shape: SyntaxShape::String,
|
||||
|
@ -49,7 +49,7 @@ fn test_signature_chained() {
|
|||
);
|
||||
assert_eq!(
|
||||
signature.get_positional(1),
|
||||
Some(PositionalArg {
|
||||
Some(&PositionalArg {
|
||||
name: "optional".to_string(),
|
||||
desc: "optional description".to_string(),
|
||||
shape: SyntaxShape::String,
|
||||
|
@ -59,7 +59,7 @@ fn test_signature_chained() {
|
|||
);
|
||||
assert_eq!(
|
||||
signature.get_positional(2),
|
||||
Some(PositionalArg {
|
||||
Some(&PositionalArg {
|
||||
name: "rest".to_string(),
|
||||
desc: "rest description".to_string(),
|
||||
shape: SyntaxShape::String,
|
||||
|
|
Loading…
Reference in New Issue
Block a user