diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2023-07-24 06:11:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-24 06:11:25 +0000 |
commit | 7b9f32300ee0a249c0872302c97635b460e45ba5 (patch) | |
tree | ae6dacdcdb74f32d949a707913c3fdac048cd00a /alacritty/src/renderer | |
parent | d20cce9401b2d449ee39013da3eb5f0f66a39c98 (diff) | |
download | r-alacritty-7b9f32300ee0a249c0872302c97635b460e45ba5.tar.gz r-alacritty-7b9f32300ee0a249c0872302c97635b460e45ba5.tar.bz2 r-alacritty-7b9f32300ee0a249c0872302c97635b460e45ba5.zip |
Use ahash instead of fnv and regular hash function
After evaluation of the ahash with the data alacritty uses it was
discovered that it's 1.5-2x times faster when getting the already
hashed values, which is the primary cases for alacritty's renderer.
Given that ahash is generally faster, all the HashSet and HashMap's
inside the alacritty were changed to use it as a hasher function.
Diffstat (limited to 'alacritty/src/renderer')
-rw-r--r-- | alacritty/src/renderer/mod.rs | 7 | ||||
-rw-r--r-- | alacritty/src/renderer/rects.rs | 3 | ||||
-rw-r--r-- | alacritty/src/renderer/text/glyph_cache.rs | 7 |
3 files changed, 9 insertions, 8 deletions
diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index fc586dc9..98e29542 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -3,6 +3,7 @@ use std::ffi::{CStr, CString}; use std::sync::atomic::{AtomicBool, Ordering}; use std::{fmt, ptr}; +use ahash::RandomState; use crossfont::Metrics; use glutin::context::{ContextApi, GlContext, PossiblyCurrentContext}; use glutin::display::{GetGlDisplay, GlDisplay}; @@ -290,13 +291,13 @@ impl GlExtensions { /// /// This function will lazyly load OpenGL extensions. fn contains(extension: &str) -> bool { - static OPENGL_EXTENSIONS: OnceCell<HashSet<&'static str>> = OnceCell::new(); + static OPENGL_EXTENSIONS: OnceCell<HashSet<&'static str, RandomState>> = OnceCell::new(); OPENGL_EXTENSIONS.get_or_init(Self::load_extensions).contains(extension) } /// Load available OpenGL extensions. - fn load_extensions() -> HashSet<&'static str> { + fn load_extensions() -> HashSet<&'static str, RandomState> { unsafe { let extensions = gl::GetString(gl::EXTENSIONS); @@ -313,7 +314,7 @@ impl GlExtensions { } else { match CStr::from_ptr(extensions as *mut _).to_str() { Ok(ext) => ext.split_whitespace().collect(), - Err(_) => HashSet::new(), + Err(_) => Default::default(), } } } diff --git a/alacritty/src/renderer/rects.rs b/alacritty/src/renderer/rects.rs index 8f6204c2..8d7a78e6 100644 --- a/alacritty/src/renderer/rects.rs +++ b/alacritty/src/renderer/rects.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::mem; +use ahash::RandomState; use crossfont::Metrics; use alacritty_terminal::grid::Dimensions; @@ -157,7 +158,7 @@ impl RenderLine { /// Lines for underline and strikeout. #[derive(Default)] pub struct RenderLines { - inner: HashMap<Flags, Vec<RenderLine>>, + inner: HashMap<Flags, Vec<RenderLine>, RandomState>, } impl RenderLines { diff --git a/alacritty/src/renderer/text/glyph_cache.rs b/alacritty/src/renderer/text/glyph_cache.rs index 72415900..a750e4e7 100644 --- a/alacritty/src/renderer/text/glyph_cache.rs +++ b/alacritty/src/renderer/text/glyph_cache.rs @@ -1,11 +1,10 @@ use std::collections::HashMap; -use std::hash::BuildHasherDefault; +use ahash::RandomState; use crossfont::{ Error as RasterizerError, FontDesc, FontKey, GlyphKey, Metrics, Rasterize, RasterizedGlyph, Rasterizer, Size, Slant, Style, Weight, }; -use fnv::FnvHasher; use log::{error, info}; use unicode_width::UnicodeWidthChar; @@ -46,7 +45,7 @@ pub struct Glyph { /// representations of the same code point. pub struct GlyphCache { /// Cache of buffered glyphs. - cache: HashMap<GlyphKey, Glyph, BuildHasherDefault<FnvHasher>>, + cache: HashMap<GlyphKey, Glyph, RandomState>, /// Rasterizer for loading new glyphs. rasterizer: Rasterizer, @@ -91,7 +90,7 @@ impl GlyphCache { let metrics = rasterizer.metrics(regular, font.size())?; Ok(Self { - cache: HashMap::default(), + cache: Default::default(), rasterizer, font_size: font.size(), font_key: regular, |