Rust library to generate static websites
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf: use fast hashmaps and hashsets

+13 -8
+3 -2
crates/framework/src/assets.rs
··· 1 1 use dyn_eq::DynEq; 2 + use rustc_hash::FxHashSet; 2 3 use std::hash::Hash; 3 - use std::{collections::HashSet, fs, path::PathBuf}; 4 + use std::{fs, path::PathBuf}; 4 5 5 6 #[derive(Default)] 6 - pub struct PageAssets(pub(crate) HashSet<Box<dyn Asset>>); 7 + pub struct PageAssets(pub(crate) FxHashSet<Box<dyn Asset>>); 7 8 8 9 impl PageAssets { 9 10 pub fn add_image(&mut self, image_path: PathBuf) -> Image {
+5 -3
crates/framework/src/lib.rs
··· 6 6 mod logging; 7 7 8 8 use std::{ 9 - collections::{HashMap, HashSet}, 10 9 fs::{self, File}, 11 10 io::{self, Write}, 12 11 path::{Path, PathBuf}, ··· 23 22 pub use maud; 24 23 pub use maudit_macros; 25 24 25 + pub use rustc_hash::FxHashMap; 26 + 26 27 use log::{info, trace}; 27 28 use page::{RouteContext, RouteParams}; 29 + use rustc_hash::FxHashSet; 28 30 29 31 pub fn coronate(router: routes::Router) -> Result<(), Box<dyn std::error::Error>> { 30 32 let build_start = SystemTime::now(); ··· 77 79 ..Default::default() 78 80 }; 79 81 80 - let mut build_pages_assets: HashSet<Box<dyn Asset>> = HashSet::new(); 82 + let mut build_pages_assets: FxHashSet<Box<dyn Asset>> = FxHashSet::default(); 81 83 82 84 for route in &router.routes { 83 85 let routes = route.routes(); ··· 86 88 let route_start = SystemTime::now(); 87 89 let mut page_assets = assets::PageAssets::default(); 88 90 let mut ctx = RouteContext { 89 - params: page::RouteParams(HashMap::new()), 91 + params: page::RouteParams(FxHashMap::default()), 90 92 assets: &mut page_assets, 91 93 }; 92 94
+4 -2
crates/framework/src/page.rs
··· 1 - use std::{collections::HashMap, path::PathBuf}; 1 + use std::path::PathBuf; 2 + 3 + use rustc_hash::FxHashMap; 2 4 3 5 use crate::assets::PageAssets; 4 6 ··· 17 19 } 18 20 19 21 #[derive(Clone, Default, Debug)] 20 - pub struct RouteParams(pub HashMap<String, String>); 22 + pub struct RouteParams(pub FxHashMap<String, String>); 21 23 22 24 impl RouteParams { 23 25 pub fn from_vec<T>(params: Vec<T>) -> Vec<RouteParams>
+1 -1
crates/macros/src/lib.rs
··· 219 219 220 220 impl Into<RouteParams> for #struct_name { 221 221 fn into(self) -> RouteParams { 222 - let mut map = std::collections::HashMap::new(); 222 + let mut map = maudit::FxHashMap::default(); 223 223 #( 224 224 map.insert(stringify!(#fields).to_string(), self.#fields.to_string()); 225 225 )*