From 66b2f9afcd81ca3c0f6017269a7c4d0db89a24bf Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Wed, 13 Nov 2024 00:42:49 +0000 Subject: [PATCH] Remove duplicate hashbrown dependency by moving to basic-toml --- Cargo.lock | 97 +++++++++++++++++++++++++++++--------------------------------------------------- Cargo.toml | 13 ++++++++++--- deny.toml | 30 ++++++++++++++++-------------- src/git.rs | 17 +++++++++++------ src/main.rs | 12 +++++++++--- src/theme.rs | 9 +++------ tree-sitter-grammar-repository/Cargo.toml | 3 ++- tree-sitter-grammar-repository/build.rs | 20 +++++++++++++++----- src/methods/filters.rs | 5 ++--- 9 files changed, 86 insertions(+), 120 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b94aab..8427b33 100644 --- a/Cargo.lock +++ a/Cargo.lock @@ -197,6 +197,15 @@ ] [[package]] +name = "basic-toml" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "823388e228f614e9558c6804262db37960ec8821856535f5c3f59913140558f8" +dependencies = [ + "serde", +] + +[[package]] name = "bindgen" version = "0.69.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -580,7 +589,7 @@ dependencies = [ "cfg-if", "crossbeam-utils", - "hashbrown 0.14.5", + "hashbrown", "lock_api", "once_cell", "parking_lot_core", @@ -689,12 +698,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5320ae4c3782150d900b79807611a59a99fc9a1d61d686faafc24b93fc8d7ca" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" @@ -1146,7 +1149,7 @@ checksum = "0ef65b256631078ef733bc5530c4e6b1c2e7d5c2830b75d4e9034ab3997d18fe" dependencies = [ "gix-hash", - "hashbrown 0.14.5", + "hashbrown", "parking_lot", ] @@ -1182,7 +1185,7 @@ "gix-traverse", "gix-utils", "gix-validate", - "hashbrown 0.14.5", + "hashbrown", "itoa", "libc", "memmap2", @@ -1526,15 +1529,10 @@ dependencies = [ "ahash", "allocator-api2", + "serde", ] [[package]] -name = "hashbrown" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" - -[[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1800,17 +1798,7 @@ checksum = "fc9da1a252bd44cd341657203722352efc9bc0c847d06ea6d2dc1cd1135e0a01" dependencies = [ "ahash", - "hashbrown 0.14.5", -] - -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown 0.15.1", + "hashbrown", ] [[package]] @@ -2199,7 +2187,7 @@ checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79" dependencies = [ "dlv-list", - "hashbrown 0.14.5", + "hashbrown", ] [[package]] @@ -2492,6 +2480,7 @@ "arc-swap", "askama", "axum", + "basic-toml", "bytes", "clap", "comrak", @@ -2500,10 +2489,12 @@ "flate2", "futures-util", "gix", + "hashbrown", "httparse", "humantime", "itertools", "md5", + "memchr", "moka", "path-clean", "rand", @@ -2519,7 +2510,6 @@ "tokio", "tokio-stream", "tokio-util", - "toml", "tower", "tower-http", "tower-layer", @@ -2542,16 +2532,13 @@ checksum = "395027076c569819ea6035ee62e664f5e03d74e281744f55261dd1afd939212b" dependencies = [ "bytecheck", - "bytes", - "hashbrown 0.14.5", - "indexmap", + "hashbrown", "munge", "ptr_meta", "rancor", "rend", "rkyv_derive", "tinyvec", - "uuid", ] [[package]] @@ -2691,15 +2678,6 @@ ] [[package]] -name = "serde_spanned" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" -dependencies = [ - "serde", -] - -[[package]] name = "serde_urlencoded" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3058,40 +3036,6 @@ "futures-sink", "pin-project-lite", "tokio", -] - -[[package]] -name = "toml" -version = "0.8.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_edit" -version = "0.22.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" -dependencies = [ - "indexmap", - "serde", - "serde_spanned", - "toml_datetime", - "winnow", ] [[package]] @@ -3204,9 +3148,11 @@ version = "0.0.1" dependencies = [ "anyhow", + "basic-toml", "cc", "globset", "heck", + "memchr", "prettyplease", "proc-macro2", "quote", @@ -3214,7 +3160,6 @@ "serde", "syn", "threadpool", - "toml", "tree-sitter-language", ] diff --git a/Cargo.toml b/Cargo.toml index 247ad48..1034e0f 100644 --- a/Cargo.toml +++ a/Cargo.toml @@ -20,6 +20,7 @@ "tokio", "http1", ] } +basic-toml = "0.1" bytes = "1.5" clap = { version = "4.5.20", default-features = false, features = [ "std", @@ -40,14 +41,22 @@ "blob-diff", "revision", ] } +hashbrown = { version = "0.14", default-features = false, features = [ + "serde", + "ahash", +] } httparse = "1.9" humantime = "2.1" itertools = "0.12.1" md5 = "0.7" +memchr = "2.7" moka = { version = "0.12.0", features = ["future"] } path-clean = "1.0.1" rand = "0.8.5" -rkyv = "0.8" +rkyv = { version = "0.8", features = [ + "bytecheck", + "alloc", +], default-features = false } rocksdb = { version = "0.22", default-features = false, features = ["snappy"] } rust-ini = "0.21.1" serde = { version = "1.0", features = ["derive", "rc"] } @@ -58,7 +67,6 @@ tokio = { version = "1.19", features = ["full", "tracing"] } tokio-stream = "0.1" tokio-util = { version = "0.7.10", features = ["io"] } -toml = { version = "0.8", default-features = false, features = ["parse"] } tower = "0.5" tower-http = { version = "0.6", features = ["cors", "timeout"] } tower-layer = "0.3" @@ -87,4 +95,3 @@ [package.metadata.deb] section = "web" - diff --git a/deny.toml b/deny.toml index 19ac81d..54336d3 100644 --- a/deny.toml +++ a/deny.toml @@ -11,17 +11,17 @@ [licenses] allow = [ - "MIT", - "Apache-2.0", - "Unicode-3.0", - "Unicode-DFS-2016", - "WTFPL", - "BSL-1.0", - "CC0-1.0", - "BSD-3-Clause", - "ISC", - "Zlib", - "BSD-2-Clause", + "MIT", + "Apache-2.0", + "Unicode-3.0", + "Unicode-DFS-2016", + "WTFPL", + "BSL-1.0", + "CC0-1.0", + "BSD-3-Clause", + "ISC", + "Zlib", + "BSD-2-Clause", ] confidence-threshold = 0.8 exceptions = [] @@ -35,12 +35,11 @@ allow = [] deny = [] skip = [ - { crate = "sync_wrapper@0.1.2", reason = "tower has not upgraded to 1.0 yet" }, - { crate = "windows-sys@0.52.0", reason = "gix pulls in two separate versions" }, - { crate = "hashbrown@0.14.5", reason = "gix has not upgraded their version of dashmap" }, + { crate = "sync_wrapper@0.1.2", reason = "tower has not upgraded to 1.0 yet" }, + { crate = "windows-sys@0.52.0", reason = "gix pulls in two separate versions" }, ] skip-tree = [ - { name = "matchers", reason = "tracing-subscriber's env-filter pulls in an ancient regex version" } + { name = "matchers", reason = "tracing-subscriber's env-filter pulls in an ancient regex version" }, ] [sources] @@ -48,4 +47,3 @@ unknown-git = "warn" allow-registry = ["https://github.com/rust-lang/crates.io-index"] allow-git = [] - diff --git a/src/git.rs b/src/git.rs index 0e0ad9d..5046e56 100644 --- a/src/git.rs +++ a/src/git.rs @@ -39,9 +39,14 @@ type ReadmeCacheKey = (PathBuf, Option>); pub struct Git { - commits: Cache<(ObjectId, bool), Arc>, - readme_cache: Cache)>>, - open_repositories: Cache, + commits: Cache<(ObjectId, bool), Arc, hashbrown::hash_map::DefaultHashBuilder>, + readme_cache: Cache< + ReadmeCacheKey, + Option<(ReadmeFormat, Arc)>, + hashbrown::hash_map::DefaultHashBuilder, + >, + open_repositories: + Cache, } impl Git { @@ -51,15 +56,15 @@ commits: Cache::builder() .time_to_live(Duration::from_secs(30)) .max_capacity(100) - .build(), + .build_with_hasher(hashbrown::hash_map::DefaultHashBuilder::default()), readme_cache: Cache::builder() .time_to_live(Duration::from_secs(30)) .max_capacity(100) - .build(), + .build_with_hasher(hashbrown::hash_map::DefaultHashBuilder::default()), open_repositories: Cache::builder() .time_to_idle(Duration::from_secs(120)) .max_capacity(100) - .build(), + .build_with_hasher(hashbrown::hash_map::DefaultHashBuilder::default()), } } } diff --git a/src/main.rs b/src/main.rs index bd3e820..20d0826 100644 --- a/src/main.rs +++ a/src/main.rs @@ -138,7 +138,7 @@ run_indexer(db.clone(), args.scan_path.clone(), args.refresh_interval); let css = { - let theme = toml::from_str::(include_str!("../themes/github_light.toml")) + let theme = basic_toml::from_str::(include_str!("../themes/github_light.toml")) .unwrap() .build_css(); let css = Box::leak( @@ -151,7 +151,7 @@ }; let dark_css = { - let theme = toml::from_str::(include_str!("../themes/onedark.toml")) + let theme = basic_toml::from_str::(include_str!("../themes/onedark.toml")) .unwrap() .build_css(); let css = Box::leak( @@ -241,7 +241,13 @@ let mut commit_family_options = Options::default(); commit_family_options.set_prefix_extractor(SliceTransform::create( "commit_prefix", - |input| input.split(|&c| c == b'\0').next().unwrap_or(input), + |input| { + if let Some(offset) = memchr::memchr(b'\0', input) { + &input[offset + 1..] + } else { + input + } + }, None, )); diff --git a/src/theme.rs b/src/theme.rs index 11aa6d1..b14a701 100644 --- a/src/theme.rs +++ a/src/theme.rs @@ -1,7 +1,4 @@ -use std::{ - collections::HashMap, - fmt::{Formatter, Write}, -}; +use std::fmt::{Formatter, Write}; use serde::{ de::{value::MapAccessDeserializer, Error, MapAccess, Visitor}, @@ -10,9 +7,9 @@ #[derive(Deserialize)] pub struct Theme { - palette: HashMap, + palette: hashbrown::HashMap, #[serde(flatten)] - definitions: HashMap, + definitions: hashbrown::HashMap, } pub enum PaletteReference { diff --git a/tree-sitter-grammar-repository/Cargo.toml b/tree-sitter-grammar-repository/Cargo.toml index 7e918ae..88c6678 100644 --- a/tree-sitter-grammar-repository/Cargo.toml +++ a/tree-sitter-grammar-repository/Cargo.toml @@ -15,8 +15,9 @@ anyhow = "1.0" cc = "1.2" serde = { version = "1.0", features = ["derive"] } -toml = "0.8" +basic-toml = "0.1" threadpool = "1.8" +memchr = "2.7" quote = "1.0" proc-macro2 = "1.0" prettyplease = "0.2" diff --git a/tree-sitter-grammar-repository/build.rs b/tree-sitter-grammar-repository/build.rs index af1707a..af06146 100644 --- a/tree-sitter-grammar-repository/build.rs +++ a/tree-sitter-grammar-repository/build.rs @@ -44,7 +44,7 @@ }; let (config, query_path) = if dylib { - let config: HelixLanguages = toml::from_str( + let config: HelixLanguages = basic_toml::from_str( &fs::read_to_string(root.join("languages.toml")) .context("failed to read languages.toml")?, ) @@ -70,11 +70,19 @@ fetch_git_repository(GRAMMAR_REPOSITORY_URL, GRAMMAR_REPOSITORY_REF, &helix_root) .context(GRAMMAR_REPOSITORY_URL)?; - let config: HelixLanguages = toml::from_str( - &fs::read_to_string(helix_root.join(GRAMMAR_REPOSITORY_CONFIG_PATH)) - .context("failed to read helix languages.toml")?, - ) - .context("failed to parse helix languages.toml")?; + let config = fs::read_to_string(helix_root.join(GRAMMAR_REPOSITORY_CONFIG_PATH)) + .context("failed to read helix languages.toml")?; + + // find the start of the language arrays & skip parsing everything before them (primarily because + // `basic_toml` can't handle some of the new syntax used in this file, and `toml` pulls in a lot + // of dependencies) + let language_defs_start = memchr::memmem::find(config.as_bytes(), b"[[language]]") + .context("languages.toml is missing languages")?; + + let config = &config[language_defs_start..]; + + let config: HelixLanguages = + basic_toml::from_str(config).context("failed to parse helix languages.toml")?; fetch_and_build_grammar(config.grammar.clone(), &sources)?; diff --git a/src/methods/filters.rs b/src/methods/filters.rs index 69c1e5c..83a4bce 100644 --- a/src/methods/filters.rs +++ a/src/methods/filters.rs @@ -1,9 +1,8 @@ // sorry clippy, we don't have a choice. askama forces this on us #![allow(clippy::unnecessary_wraps, clippy::trivially_copy_pass_by_ref)] use std::{ borrow::Borrow, - collections::HashMap, sync::{Arc, LazyLock}, }; @@ -46,8 +45,8 @@ } pub fn gravatar(email: &str) -> Result<&'static str, askama::Error> { - static CACHE: LazyLock>> = - LazyLock::new(|| ArcSwap::new(Arc::new(HashMap::new()))); + static CACHE: LazyLock>> = + LazyLock::new(|| ArcSwap::new(Arc::new(hashbrown::HashMap::new()))); if let Some(res) = CACHE.load().get(email).copied() { return Ok(res); -- rgit 0.1.3