@@ -5,6 +5,7 @@ use std::{path::Path, rc::Rc};
55
66use oxc_allocator:: Allocator ;
77use oxc_ast:: ast_kind:: AST_TYPE_MAX ;
8+ use oxc_data_structures:: box_macros:: boxed_array;
89use oxc_semantic:: AstNode ;
910
1011#[ cfg( all( feature = "oxlint2" , not( feature = "disable_oxlint2" ) ) ) ]
@@ -169,23 +170,16 @@ impl Linter {
169170 //
170171 // See https://github.com/oxc-project/oxc/pull/6600 for more context.
171172 if semantic. nodes ( ) . len ( ) > 200_000 {
172- const AST_TYPES_LEN : usize = AST_TYPE_MAX as usize + 1 ;
173-
174173 // Collect rules into a Vec so that we can iterate over the rules multiple times
175174 let rules = rules. collect :: < Vec < _ > > ( ) ;
176175
177176 // TODO: It seems like there is probably a more intelligent way to preallocate space here. This will
178177 // likely incur quite a few unnecessary reallocs currently. We theoretically could compute this at
179178 // compile-time since we know all of the rules and their AST node type information ahead of time.
180179 //
181- // Convert to boxed array to help compiler see that indexing into it with an `AstType`
182- // cannot go out of bounds, and remove bounds checks. The `unwrap` is infallible and should be optimized out.
183- let rules_by_ast_type = vec ! [ Vec :: new( ) ; AST_TYPES_LEN ] ;
184- #[ expect( clippy:: missing_panics_doc, reason = "infallible" ) ]
185- let mut rules_by_ast_type =
186- Box :: < [ _ ; AST_TYPES_LEN ] > :: try_from ( rules_by_ast_type. into_boxed_slice ( ) )
187- . ok ( )
188- . unwrap ( ) ;
180+ // Use boxed array to help compiler see that indexing into it with an `AstType`
181+ // cannot go out of bounds, and remove bounds checks.
182+ let mut rules_by_ast_type = boxed_array ! [ Vec :: new( ) ; AST_TYPE_MAX as usize + 1 ] ;
189183 // TODO: Compute needed capacity. This is a slight overestimate as not 100% of rules will need to run on all
190184 // node types, but it at least guarantees we won't need to realloc.
191185 let mut rules_any_ast_type = Vec :: with_capacity ( rules. len ( ) ) ;
0 commit comments