mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:35 +00:00
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:
parent
4b65446de6
commit
f45d1c2b84
6 changed files with 326 additions and 1149 deletions
|
@ -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,
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
Loading…
Add table
Add a link
Reference in a new issue