@@ -21,7 +21,13 @@ type ParameterDef = (ast::Arg, Option<ast::Expr>);
21
21
pub ( crate ) fn validate_arguments (
22
22
arguments : ast:: Arguments ,
23
23
) -> Result < ast:: Arguments , LexicalError > {
24
- let mut all_args: Vec < & ast:: Arg > = vec ! [ ] ;
24
+ let mut all_args: Vec < & ast:: Arg > = Vec :: with_capacity (
25
+ arguments. posonlyargs . len ( )
26
+ + arguments. args . len ( )
27
+ + arguments. vararg . is_some ( ) as usize
28
+ + arguments. kwonlyargs . len ( )
29
+ + arguments. kwarg . is_some ( ) as usize ,
30
+ ) ;
25
31
26
32
all_args. extend ( arguments. posonlyargs . iter ( ) ) ;
27
33
all_args. extend ( arguments. args . iter ( ) ) ;
@@ -36,11 +42,11 @@ pub(crate) fn validate_arguments(
36
42
all_args. push ( a) ;
37
43
}
38
44
39
- let mut all_arg_names = FxHashSet :: with_hasher ( Default :: default ( ) ) ;
45
+ let mut all_arg_names = FxHashSet :: with_capacity_and_hasher ( all_args . len ( ) , Default :: default ( ) ) ;
40
46
for arg in all_args {
41
47
let arg_name = & arg. arg ;
42
48
// Check for duplicate arguments in the function definition.
43
- if !all_arg_names. insert ( arg_name) {
49
+ if !all_arg_names. insert ( arg_name. as_str ( ) ) {
44
50
return Err ( LexicalError {
45
51
error : LexicalErrorType :: DuplicateArgumentError ( arg_name. to_string ( ) ) ,
46
52
location : arg. start ( ) ,
@@ -104,16 +110,14 @@ pub(crate) fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ArgumentLis
104
110
Some ( ( start, end, name) ) => {
105
111
// Check for duplicate keyword arguments in the call.
106
112
if let Some ( keyword_name) = & name {
107
- if keyword_names. contains ( keyword_name) {
113
+ if ! keyword_names. insert ( keyword_name. to_string ( ) ) {
108
114
return Err ( LexicalError {
109
115
error : LexicalErrorType :: DuplicateKeywordArgumentError (
110
116
keyword_name. to_string ( ) ,
111
117
) ,
112
118
location : start,
113
119
} ) ;
114
120
}
115
-
116
- keyword_names. insert ( keyword_name. clone ( ) ) ;
117
121
} else {
118
122
double_starred = true ;
119
123
}
0 commit comments