treewide: replace std hashers with rustc_hash alternatives; fix clippy
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I766c36cb53d3d7f9e85b91a67c4131a66a6a6964
This commit is contained in:
parent
d73bb4580d
commit
f831e58723
53 changed files with 343 additions and 394 deletions
|
|
@ -186,17 +186,19 @@ impl PluginManager {
|
|||
fn resolve_load_order(
|
||||
manifests: &[pinakes_plugin_api::PluginManifest],
|
||||
) -> Vec<pinakes_plugin_api::PluginManifest> {
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
// Index manifests by name for O(1) lookup
|
||||
let by_name: HashMap<&str, usize> = manifests
|
||||
let by_name: FxHashMap<&str, usize> = manifests
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, m)| (m.plugin.name.as_str(), i))
|
||||
.collect();
|
||||
|
||||
// Check for missing dependencies and warn early
|
||||
let known: HashSet<&str> = by_name.keys().copied().collect();
|
||||
let known: FxHashSet<&str> = by_name.keys().copied().collect();
|
||||
for manifest in manifests {
|
||||
for dep in &manifest.plugin.dependencies {
|
||||
if !known.contains(dep.as_str()) {
|
||||
|
|
@ -250,7 +252,7 @@ impl PluginManager {
|
|||
|
||||
// Anything not in `result` is part of a cycle or has a missing dep
|
||||
if result.len() < manifests.len() {
|
||||
let loaded: HashSet<&str> =
|
||||
let loaded: FxHashSet<&str> =
|
||||
result.iter().map(|m| m.plugin.name.as_str()).collect();
|
||||
for manifest in manifests {
|
||||
if !loaded.contains(manifest.plugin.name.as_str()) {
|
||||
|
|
@ -669,9 +671,9 @@ impl PluginManager {
|
|||
/// none declare theme extensions.
|
||||
pub async fn list_ui_theme_extensions(
|
||||
&self,
|
||||
) -> std::collections::HashMap<String, String> {
|
||||
) -> rustc_hash::FxHashMap<String, String> {
|
||||
let registry = self.registry.read().await;
|
||||
let mut merged = std::collections::HashMap::new();
|
||||
let mut merged = rustc_hash::FxHashMap::default();
|
||||
for plugin in registry.list_all() {
|
||||
if !plugin.enabled {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@
|
|||
//! priority 100. A circuit breaker disables plugins after consecutive failures.
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
use tokio::sync::RwLock;
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
|
|
@ -75,22 +75,22 @@ struct CachedCapabilities {
|
|||
/// Keyed by `(kind, plugin_id)` -> list of supported type strings.
|
||||
/// Separate entries for each kind avoid collisions when a plugin
|
||||
/// implements both `metadata_extractor` and `thumbnail_generator`.
|
||||
supported_types: HashMap<(String, String), Vec<String>>,
|
||||
supported_types: FxHashMap<(String, String), Vec<String>>,
|
||||
/// `plugin_id` -> list of interested event type strings
|
||||
interested_events: HashMap<String, Vec<String>>,
|
||||
interested_events: FxHashMap<String, Vec<String>>,
|
||||
/// `plugin_id` -> list of media type definitions (for `MediaTypeProvider`)
|
||||
media_type_definitions: HashMap<String, Vec<PluginMediaTypeDefinition>>,
|
||||
media_type_definitions: FxHashMap<String, Vec<PluginMediaTypeDefinition>>,
|
||||
/// `plugin_id` -> list of theme definitions (for `ThemeProvider`)
|
||||
theme_definitions: HashMap<String, Vec<PluginThemeDefinition>>,
|
||||
theme_definitions: FxHashMap<String, Vec<PluginThemeDefinition>>,
|
||||
}
|
||||
|
||||
impl CachedCapabilities {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
supported_types: HashMap::new(),
|
||||
interested_events: HashMap::new(),
|
||||
media_type_definitions: HashMap::new(),
|
||||
theme_definitions: HashMap::new(),
|
||||
supported_types: FxHashMap::default(),
|
||||
interested_events: FxHashMap::default(),
|
||||
media_type_definitions: FxHashMap::default(),
|
||||
theme_definitions: FxHashMap::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -101,7 +101,7 @@ pub struct PluginPipeline {
|
|||
manager: Arc<PluginManager>,
|
||||
timeouts: PluginTimeoutConfig,
|
||||
max_consecutive_failures: u32,
|
||||
health: RwLock<HashMap<String, PluginHealth>>,
|
||||
health: RwLock<FxHashMap<String, PluginHealth>>,
|
||||
capabilities: RwLock<CachedCapabilities>,
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ impl PluginPipeline {
|
|||
manager,
|
||||
timeouts,
|
||||
max_consecutive_failures,
|
||||
health: RwLock::new(HashMap::new()),
|
||||
health: RwLock::new(FxHashMap::default()),
|
||||
capabilities: RwLock::new(CachedCapabilities::new()),
|
||||
}
|
||||
}
|
||||
|
|
@ -826,7 +826,7 @@ impl PluginPipeline {
|
|||
}
|
||||
|
||||
// Deduplicate by ID, keeping the highest-scoring entry
|
||||
let mut seen: HashMap<String, usize> = HashMap::new();
|
||||
let mut seen: FxHashMap<String, usize> = FxHashMap::default();
|
||||
let mut deduped: Vec<SearchResultItem> = Vec::new();
|
||||
for item in all_results {
|
||||
if let Some(&idx) = seen.get(&item.id) {
|
||||
|
|
@ -1363,7 +1363,7 @@ mod tests {
|
|||
year: Some(2024),
|
||||
duration_secs: None,
|
||||
description: None,
|
||||
extra: HashMap::new(),
|
||||
extra: FxHashMap::default(),
|
||||
};
|
||||
|
||||
merge_metadata(&mut base, &resp);
|
||||
|
|
@ -1379,7 +1379,7 @@ mod tests {
|
|||
let mut base = ExtractedMetadata::default();
|
||||
base.extra.insert("key1".to_string(), "val1".to_string());
|
||||
|
||||
let mut extra = HashMap::new();
|
||||
let mut extra = FxHashMap::default();
|
||||
extra.insert("key2".to_string(), "val2".to_string());
|
||||
extra.insert("key1".to_string(), "overwritten".to_string());
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
//! Plugin registry for managing loaded plugins
|
||||
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{Result, anyhow};
|
||||
use pinakes_plugin_api::{PluginManifest, PluginMetadata};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use super::runtime::WasmPlugin;
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ pub struct RegisteredPlugin {
|
|||
/// Plugin registry maintains the state of all loaded plugins
|
||||
pub struct PluginRegistry {
|
||||
/// Map of plugin ID to registered plugin
|
||||
plugins: HashMap<String, RegisteredPlugin>,
|
||||
plugins: FxHashMap<String, RegisteredPlugin>,
|
||||
}
|
||||
|
||||
impl PluginRegistry {
|
||||
|
|
@ -29,7 +30,7 @@ impl PluginRegistry {
|
|||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
plugins: HashMap::new(),
|
||||
plugins: FxHashMap::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -156,9 +157,8 @@ impl Default for PluginRegistry {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use pinakes_plugin_api::{Capabilities, manifest::ManifestCapabilities};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
|
@ -181,7 +181,7 @@ mod tests {
|
|||
priority: 0,
|
||||
},
|
||||
capabilities: ManifestCapabilities::default(),
|
||||
config: HashMap::new(),
|
||||
config: FxHashMap::default(),
|
||||
ui: Default::default(),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@
|
|||
//! Requests are serialized to JSON, passed to the plugin, and responses
|
||||
//! are deserialized from JSON written by the plugin via `host_set_result`.
|
||||
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Request to check if a plugin can handle a file
|
||||
|
|
@ -55,7 +56,7 @@ pub struct ExtractMetadataResponse {
|
|||
#[serde(default)]
|
||||
pub description: Option<String>,
|
||||
#[serde(default)]
|
||||
pub extra: HashMap<String, String>,
|
||||
pub extra: FxHashMap<String, String>,
|
||||
}
|
||||
|
||||
/// Request to generate a thumbnail
|
||||
|
|
@ -140,7 +141,7 @@ pub struct PluginThemeDefinition {
|
|||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct LoadThemeResponse {
|
||||
pub css: Option<String>,
|
||||
pub colors: HashMap<String, String>,
|
||||
pub colors: FxHashMap<String, String>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ impl Default for WasmPlugin {
|
|||
context: PluginContext {
|
||||
data_dir: std::env::temp_dir(),
|
||||
cache_dir: std::env::temp_dir(),
|
||||
config: std::collections::HashMap::new(),
|
||||
config: Default::default(),
|
||||
capabilities: Default::default(),
|
||||
},
|
||||
}
|
||||
|
|
@ -774,8 +774,6 @@ impl HostFunctions {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use pinakes_plugin_api::PluginContext;
|
||||
|
||||
use super::*;
|
||||
|
|
@ -795,7 +793,7 @@ mod tests {
|
|||
let context = PluginContext {
|
||||
data_dir: "/tmp/data".into(),
|
||||
cache_dir: "/tmp/cache".into(),
|
||||
config: HashMap::new(),
|
||||
config: Default::default(),
|
||||
capabilities,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue