@@ -614,7 +614,7 @@ impl<'src> Parser<'src> {
614614 // import ,
615615 // import x, y,
616616
617- let names = self
617+ let mut names = self
618618 . parse_comma_separated_list_into_vec ( RecoveryContextKind :: ImportNames , |p| {
619619 p. parse_alias ( ImportStyle :: Import )
620620 } ) ;
@@ -625,6 +625,8 @@ impl<'src> Parser<'src> {
625625 self . add_error ( ParseErrorType :: EmptyImportNames , self . current_token_range ( ) ) ;
626626 }
627627
628+ names. shrink_to_fit ( ) ;
629+
628630 ast:: StmtImport {
629631 names,
630632 is_lazy,
@@ -740,6 +742,8 @@ impl<'src> Parser<'src> {
740742 self . expect ( TokenKind :: Rpar ) ;
741743 }
742744
745+ names. shrink_to_fit ( ) ;
746+
743747 ast:: StmtImportFrom {
744748 module,
745749 names,
@@ -1444,6 +1448,8 @@ impl<'src> Parser<'src> {
14441448 elif_else_clauses. push ( self . parse_elif_or_else_clause ( ElifOrElse :: Else ) ) ;
14451449 }
14461450
1451+ elif_else_clauses. shrink_to_fit ( ) ;
1452+
14471453 ast:: StmtIf {
14481454 test : Box :: new ( test. expr ) ,
14491455 body,
@@ -1539,7 +1545,7 @@ impl<'src> Parser<'src> {
15391545 // except* ExceptionGroup:
15401546 // pass
15411547 let mut mixed_except_ranges = Vec :: new ( ) ;
1542- let handlers = self . parse_clauses ( Clause :: Except , |p| {
1548+ let mut handlers = self . parse_clauses ( Clause :: Except , |p| {
15431549 let ( handler, kind) = p. parse_except_clause ( ) ;
15441550 if let ExceptClauseKind :: Star ( range) = kind {
15451551 p. add_unsupported_syntax_error ( UnsupportedSyntaxErrorKind :: ExceptStar , range) ;
@@ -1551,6 +1557,8 @@ impl<'src> Parser<'src> {
15511557 }
15521558 handler
15531559 } ) ;
1560+ handlers. shrink_to_fit ( ) ;
1561+
15541562 // Empty handler has `is_star` false.
15551563 let is_star = is_star. unwrap_or_default ( ) ;
15561564 for handler_err_range in mixed_except_ranges {
@@ -2170,7 +2178,9 @@ impl<'src> Parser<'src> {
21702178 fn parse_with_statement ( & mut self , start : TextSize ) -> ast:: StmtWith {
21712179 self . bump ( TokenKind :: With ) ;
21722180
2173- let items = self . parse_with_items ( ) ;
2181+ let mut items = self . parse_with_items ( ) ;
2182+ items. shrink_to_fit ( ) ;
2183+
21742184 self . expect ( TokenKind :: Colon ) ;
21752185
21762186 let body = self . parse_body ( Clause :: With ) ;
@@ -2985,6 +2995,8 @@ impl<'src> Parser<'src> {
29852995 self . expect ( TokenKind :: Newline ) ;
29862996 }
29872997
2998+ decorators. shrink_to_fit ( ) ;
2999+
29883000 match self . current_token_kind ( ) {
29893001 TokenKind :: Def => Stmt :: FunctionDef ( self . parse_function_definition ( decorators, start) ) ,
29903002 TokenKind :: Class => Stmt :: ClassDef ( self . parse_class_definition ( decorators, start) ) ,
@@ -3528,6 +3540,10 @@ impl<'src> Parser<'src> {
35283540 self . expect ( TokenKind :: Rpar ) ;
35293541 }
35303542
3543+ parameters. args . shrink_to_fit ( ) ;
3544+ parameters. kwonlyargs . shrink_to_fit ( ) ;
3545+ parameters. posonlyargs . shrink_to_fit ( ) ;
3546+
35313547 parameters. range = self . node_range ( start) ;
35323548
35333549 parameters
0 commit comments