Skip to content

Commit

Permalink
Make it lazy static
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jul 19, 2024
1 parent 2970faa commit 0f0f5b2
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions crates/red_knot_module_resolver/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::borrow::Cow;
use std::iter::FusedIterator;
use std::sync::Arc;

use once_cell::sync::Lazy;
use rustc_hash::{FxBuildHasher, FxHashSet};

use ruff_db::files::{File, FilePath};
Expand Down Expand Up @@ -451,39 +452,42 @@ pub(crate) mod internal {
///
/// TODO(Alex): write a script to generate this list,
/// similar to what we do in `crates/ruff_python_stdlib/src/sys.rs`
const BUILTIN_MODULES: &[&str] = &[
"_abc",
"_ast",
"_codecs",
"_collections",
"_functools",
"_imp",
"_io",
"_locale",
"_operator",
"_signal",
"_sre",
"_stat",
"_string",
"_symtable",
"_thread",
"_tokenize",
"_tracemalloc",
"_typing",
"_warnings",
"_weakref",
"atexit",
"builtins",
"errno",
"faulthandler",
"gc",
"itertools",
"marshal",
"posix",
"pwd",
"sys",
"time",
];
static BUILTIN_MODULES: Lazy<FxHashSet<&str>> = Lazy::new(|| {
const BUILTIN_MODULE_NAMES: &[&str] = &[
"_abc",
"_ast",
"_codecs",
"_collections",
"_functools",
"_imp",
"_io",
"_locale",
"_operator",
"_signal",
"_sre",
"_stat",
"_string",
"_symtable",
"_thread",
"_tokenize",
"_tracemalloc",
"_typing",
"_warnings",
"_weakref",
"atexit",
"builtins",
"errno",
"faulthandler",
"gc",
"itertools",
"marshal",
"posix",
"pwd",
"sys",
"time",
];
BUILTIN_MODULE_NAMES.iter().copied().collect()
});

/// Given a module name and a list of search paths in which to lookup modules,
/// attempt to resolve the module name
Expand Down

0 comments on commit 0f0f5b2

Please sign in to comment.