Remove HashMap and HashSet for known-standard-library detection (#5345)

## Summary

This is a lot more concise and probably much more performant (with fewer
instructions).
This commit is contained in:
Charlie Marsh 2023-06-23 15:59:03 -04:00 committed by GitHub
parent 4b65446de6
commit f45d1c2b84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 326 additions and 1149 deletions

View file

@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use strum_macros::EnumIter;
use ruff_macros::CacheKey;
use ruff_python_stdlib::sys::KNOWN_STANDARD_LIBRARY;
use ruff_python_stdlib::sys::is_known_standard_library;
use crate::settings::types::PythonVersion;
use crate::warn_user_once;
@ -82,11 +82,7 @@ pub(crate) fn categorize<'a>(
(&ImportSection::Known(ImportType::Future), Reason::Future)
} else if let Some((import_type, reason)) = known_modules.categorize(module_name) {
(import_type, reason)
} else if KNOWN_STANDARD_LIBRARY
.get(&target_version.as_tuple())
.unwrap()
.contains(module_base)
{
} else if is_known_standard_library(target_version.minor(), module_base) {
(
&ImportSection::Known(ImportType::StandardLibrary),
Reason::KnownStandardLibrary,

View file

@ -52,6 +52,14 @@ impl PythonVersion {
}
}
pub const fn major(&self) -> u32 {
self.as_tuple().0
}
pub const fn minor(&self) -> u32 {
self.as_tuple().1
}
pub fn get_minimum_supported_version(requires_version: &VersionSpecifiers) -> Option<Self> {
let mut minimum_version = None;
for python_version in PythonVersion::iter() {

View file

@ -13,5 +13,3 @@ license = { workspace = true }
[lib]
[dependencies]
once_cell = { workspace = true }
rustc-hash = { workspace = true }

File diff suppressed because it is too large Load diff