mirror of
https://github.com/crate-ci/typos.git
synced 2026-10-17 17:45:10 +02:00
Merge pull request #1590 from epage/str
refactor: Migrate away from KString
This commit is contained in:
Generated
+30
-11
@@ -173,6 +173,15 @@ dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "castaway"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dec551ab6e7578819132c713a93c022a05d60159dc86e7a7050223577484c55a"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
@@ -277,6 +286,20 @@ dependencies = [
|
||||
"colorchoice",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "compact_str"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79fcda08c33bb58b97008b2cdada6622500e949e060f5913361763121abd2416"
|
||||
dependencies = [
|
||||
"castaway",
|
||||
"cfg-if",
|
||||
"itoa",
|
||||
"serde",
|
||||
"static_assertions",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "condtype"
|
||||
version = "1.3.0"
|
||||
@@ -760,16 +783,6 @@ version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
|
||||
|
||||
[[package]]
|
||||
name = "kstring"
|
||||
version = "2.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "558bf9508a558512042d3095138b1f7b8fe90c5467d94f9f1da28b3731c5dbd1"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
@@ -1156,6 +1169,12 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.23"
|
||||
@@ -1639,6 +1658,7 @@ dependencies = [
|
||||
"clap-cargo",
|
||||
"clap-verbosity-flag",
|
||||
"colorchoice-clap",
|
||||
"compact_str",
|
||||
"content_inspector",
|
||||
"derive_more",
|
||||
"derive_setters",
|
||||
@@ -1650,7 +1670,6 @@ dependencies = [
|
||||
"human-panic",
|
||||
"ignore",
|
||||
"itertools",
|
||||
"kstring",
|
||||
"log",
|
||||
"maplit",
|
||||
"proc-exit",
|
||||
|
||||
@@ -65,7 +65,6 @@ derive_more = { version = "2.1", features = ["from", "display"] }
|
||||
derive_setters = "0.1"
|
||||
itertools = "0.15"
|
||||
serde_json = "1.0"
|
||||
kstring = { version = "2.0.2", features = ["serde"] }
|
||||
typed-arena = "2.0.2"
|
||||
thread_local = "1.1.9"
|
||||
globset = "0.4.18"
|
||||
@@ -80,6 +79,7 @@ schemars = { version = "1.2.1", features = ["preserve_order","semver1"], optiona
|
||||
annotate-snippets = "0.12.13"
|
||||
terminal_size = "0.4.3"
|
||||
supports-unicode = "3.0.0"
|
||||
compact_str = { version = "0.10.0", features = ["serde"] }
|
||||
|
||||
[dev-dependencies]
|
||||
assert_fs = "1.1"
|
||||
|
||||
Generated
+9
-9
@@ -2,7 +2,7 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use kstring::KString;
|
||||
use compact_str::CompactString;
|
||||
|
||||
use crate::file_type_specifics;
|
||||
|
||||
@@ -260,7 +260,7 @@ pub struct TypeEngineConfig {
|
||||
feature = "unstable-schema",
|
||||
schemars(schema_with = "hashmap_string_t::<GlobEngineConfig>")
|
||||
)]
|
||||
pub patterns: HashMap<KString, GlobEngineConfig>,
|
||||
pub patterns: HashMap<CompactString, GlobEngineConfig>,
|
||||
}
|
||||
|
||||
impl TypeEngineConfig {
|
||||
@@ -269,7 +269,7 @@ impl TypeEngineConfig {
|
||||
|
||||
for no_check_type in file_type_specifics::NO_CHECK_TYPES {
|
||||
patterns.insert(
|
||||
KString::from(*no_check_type),
|
||||
CompactString::const_new(no_check_type),
|
||||
GlobEngineConfig {
|
||||
extend_glob: Vec::new(),
|
||||
engine: EngineConfig {
|
||||
@@ -282,7 +282,7 @@ impl TypeEngineConfig {
|
||||
|
||||
for (typ, dict_config) in file_type_specifics::TYPE_SPECIFIC_DICTS {
|
||||
patterns.insert(
|
||||
KString::from(*typ),
|
||||
CompactString::const_new(typ),
|
||||
GlobEngineConfig {
|
||||
extend_glob: Vec::new(),
|
||||
engine: EngineConfig {
|
||||
@@ -317,7 +317,7 @@ impl TypeEngineConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn patterns(&self) -> impl Iterator<Item = (KString, GlobEngineConfig)> + use<> {
|
||||
pub fn patterns(&self) -> impl Iterator<Item = (CompactString, GlobEngineConfig)> + use<> {
|
||||
let mut engine = Self::from_defaults();
|
||||
engine.update(self);
|
||||
engine.patterns.into_iter()
|
||||
@@ -331,7 +331,7 @@ impl TypeEngineConfig {
|
||||
#[cfg_attr(feature = "unstable-schema", derive(schemars::JsonSchema))]
|
||||
pub struct GlobEngineConfig {
|
||||
#[cfg_attr(feature = "unstable-schema", schemars(schema_with = "vec_string"))]
|
||||
pub extend_glob: Vec<KString>,
|
||||
pub extend_glob: Vec<CompactString>,
|
||||
#[serde(flatten)]
|
||||
pub engine: EngineConfig,
|
||||
}
|
||||
@@ -478,7 +478,7 @@ pub struct DictConfig {
|
||||
feature = "unstable-schema",
|
||||
schemars(schema_with = "hashmap_string_string")
|
||||
)]
|
||||
pub extend_identifiers: HashMap<KString, KString>,
|
||||
pub extend_identifiers: HashMap<CompactString, CompactString>,
|
||||
#[serde(with = "serde_regex")]
|
||||
#[cfg_attr(feature = "unstable-schema", schemars(schema_with = "vec_string"))]
|
||||
pub extend_ignore_words_re: Vec<regex::Regex>,
|
||||
@@ -486,7 +486,7 @@ pub struct DictConfig {
|
||||
feature = "unstable-schema",
|
||||
schemars(schema_with = "hashmap_string_string")
|
||||
)]
|
||||
pub extend_words: HashMap<KString, KString>,
|
||||
pub extend_words: HashMap<CompactString, CompactString>,
|
||||
}
|
||||
|
||||
impl DictConfig {
|
||||
@@ -725,7 +725,7 @@ mod test {
|
||||
let mut actual = base;
|
||||
actual.update(&extended);
|
||||
|
||||
let expected: Vec<KString> = vec!["*.foo".into(), "*.bar".into()];
|
||||
let expected: Vec<CompactString> = vec!["*.foo".into(), "*.bar".into()];
|
||||
assert_data_eq!(actual.extend_glob.into_json(), expected.into_json());
|
||||
}
|
||||
|
||||
|
||||
Generated
+12
-9
@@ -1,11 +1,11 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::Path;
|
||||
|
||||
use kstring::KString;
|
||||
use compact_str::CompactString;
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub(crate) struct TypesBuilder {
|
||||
definitions: BTreeMap<KString, Vec<(KString, usize)>>,
|
||||
definitions: BTreeMap<CompactString, Vec<(CompactString, usize)>>,
|
||||
}
|
||||
|
||||
impl TypesBuilder {
|
||||
@@ -18,8 +18,11 @@ impl TypesBuilder {
|
||||
crate::default_types::DEFAULT_TYPES
|
||||
.iter()
|
||||
.map(|(name, glob)| {
|
||||
let name = KString::from(*name);
|
||||
let globs = glob.iter().map(|s| (KString::from(*s), 0)).collect();
|
||||
let name = CompactString::const_new(name);
|
||||
let globs = glob
|
||||
.iter()
|
||||
.map(|s| (CompactString::const_new(s), 0))
|
||||
.collect();
|
||||
(name, globs)
|
||||
}),
|
||||
);
|
||||
@@ -29,7 +32,7 @@ impl TypesBuilder {
|
||||
self.definitions.contains_key(name)
|
||||
}
|
||||
|
||||
pub(crate) fn add(&mut self, name: impl Into<KString>, glob: impl Into<KString>) {
|
||||
pub(crate) fn add(&mut self, name: impl Into<CompactString>, glob: impl Into<CompactString>) {
|
||||
let name = name.into();
|
||||
let glob = glob.into();
|
||||
let weight = self.definitions.len();
|
||||
@@ -56,7 +59,7 @@ impl TypesBuilder {
|
||||
.iter()
|
||||
.map(|(_, _, name, glob)| (*glob, *name))
|
||||
.collect::<BTreeMap<_, _>>();
|
||||
let mut unique_definitions = BTreeMap::<KString, Vec<KString>>::new();
|
||||
let mut unique_definitions = BTreeMap::<CompactString, Vec<CompactString>>::new();
|
||||
for (glob, name) in rev_definitions {
|
||||
unique_definitions
|
||||
.entry(name.clone())
|
||||
@@ -111,15 +114,15 @@ enum GlobPart<'s> {
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub(crate) struct Types {
|
||||
definitions: BTreeMap<KString, Vec<KString>>,
|
||||
glob_to_name: Vec<KString>,
|
||||
definitions: BTreeMap<CompactString, Vec<CompactString>>,
|
||||
glob_to_name: Vec<CompactString>,
|
||||
set: globset::GlobSet,
|
||||
/// Temporary storage for globs that match.
|
||||
matches: std::sync::Arc<thread_local::ThreadLocal<std::cell::RefCell<Vec<usize>>>>,
|
||||
}
|
||||
|
||||
impl Types {
|
||||
pub(crate) fn definitions(&self) -> &BTreeMap<KString, Vec<KString>> {
|
||||
pub(crate) fn definitions(&self) -> &BTreeMap<CompactString, Vec<CompactString>> {
|
||||
&self.definitions
|
||||
}
|
||||
|
||||
|
||||
Generated
+11
-9
@@ -1,5 +1,7 @@
|
||||
use compact_str::CompactString;
|
||||
|
||||
pub struct ConfigStorage {
|
||||
arena: std::sync::Mutex<typed_arena::Arena<kstring::KString>>,
|
||||
arena: std::sync::Mutex<typed_arena::Arena<CompactString>>,
|
||||
}
|
||||
|
||||
impl ConfigStorage {
|
||||
@@ -19,7 +21,7 @@ impl ConfigStorage {
|
||||
self.arena
|
||||
.lock()
|
||||
.unwrap()
|
||||
.alloc(kstring::KString::from_ref(other))
|
||||
.alloc(CompactString::from(other))
|
||||
.as_str(),
|
||||
)
|
||||
}
|
||||
@@ -81,7 +83,7 @@ impl<'s> ConfigEngine<'s> {
|
||||
pub fn file_types(
|
||||
&self,
|
||||
cwd: &std::path::Path,
|
||||
) -> &std::collections::BTreeMap<kstring::KString, Vec<kstring::KString>> {
|
||||
) -> &std::collections::BTreeMap<CompactString, Vec<CompactString>> {
|
||||
debug_assert!(cwd.is_absolute(), "{} is not absolute", cwd.display());
|
||||
let dir = self
|
||||
.configs
|
||||
@@ -199,7 +201,7 @@ impl<'s> ConfigEngine<'s> {
|
||||
}
|
||||
} else {
|
||||
for glob in type_engine.extend_glob.iter() {
|
||||
type_matcher.add(type_name.as_ref(), glob.as_ref());
|
||||
type_matcher.add(type_name.clone(), glob.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +316,7 @@ impl<T> Default for Intern<T> {
|
||||
struct DirConfig {
|
||||
walk: usize,
|
||||
default: FileConfig,
|
||||
types: std::collections::HashMap<kstring::KString, FileConfig>,
|
||||
types: std::collections::HashMap<CompactString, FileConfig>,
|
||||
type_matcher: crate::file_type::Types,
|
||||
}
|
||||
|
||||
@@ -397,7 +399,7 @@ mod test {
|
||||
let mut engine = ConfigEngine::new(&storage);
|
||||
engine.set_isolated(true);
|
||||
|
||||
let type_name = kstring::KString::from_static("toml");
|
||||
let type_name = CompactString::const_new("toml");
|
||||
|
||||
let config = crate::config::Config {
|
||||
default: crate::config::EngineConfig {
|
||||
@@ -453,7 +455,7 @@ mod test {
|
||||
let mut engine = ConfigEngine::new(&storage);
|
||||
engine.set_isolated(true);
|
||||
|
||||
let type_name = kstring::KString::from_static(NEVER_EXIST_TYPE);
|
||||
let type_name = CompactString::const_new(NEVER_EXIST_TYPE);
|
||||
|
||||
let config = crate::config::Config {
|
||||
type_: crate::config::TypeEngineConfig {
|
||||
@@ -493,7 +495,7 @@ mod test {
|
||||
let mut engine = ConfigEngine::new(&storage);
|
||||
engine.set_isolated(true);
|
||||
|
||||
let type_name = kstring::KString::from_static(NEVER_EXIST_TYPE);
|
||||
let type_name = CompactString::const_new(NEVER_EXIST_TYPE);
|
||||
|
||||
let config = crate::config::Config {
|
||||
default: crate::config::EngineConfig {
|
||||
@@ -527,7 +529,7 @@ mod test {
|
||||
let mut engine = ConfigEngine::new(&storage);
|
||||
engine.set_isolated(true);
|
||||
|
||||
let type_name = kstring::KString::from_static(NEVER_EXIST_TYPE);
|
||||
let type_name = CompactString::const_new(NEVER_EXIST_TYPE);
|
||||
|
||||
let config = crate::config::Config {
|
||||
default: crate::config::EngineConfig {
|
||||
|
||||
Reference in New Issue
Block a user