diff --git a/Cargo.toml b/Cargo.toml index 7e8c79c..a6dea2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,8 +35,8 @@ term_size = { version = "0.3.1", optional = true } crossbeam-channel = "0.3.9" lazy_static = "1.3.0" chrono = "0.4.7" -hashbrown = "0.5.0" cfg-if = "0.1.9" +ahash = "0.2.12" [dependencies.num] default-features = false diff --git a/src/backend/blt.rs b/src/backend/blt.rs index ce1005f..3e85708 100644 --- a/src/backend/blt.rs +++ b/src/backend/blt.rs @@ -5,7 +5,7 @@ use bear_lib_terminal; -use hashbrown::HashSet; +use std::collections::HashSet; use self::bear_lib_terminal::geometry::Size; use self::bear_lib_terminal::terminal::{ @@ -18,6 +18,9 @@ use crate::event::{Event, Key, MouseButton, MouseEvent}; use crate::theme::{BaseColor, Color, ColorPair, Effect}; use crate::vec::Vec2; +// Use AHash instead of the slower SipHash +type HashMap = std::collections::HashMap; + enum ColorRole { Foreground, Background, @@ -47,7 +50,7 @@ impl Backend { ]); let c = Backend { - buttons_pressed: HashSet::new(), + buttons_pressed: HashSet::default(), mouse_position: Vec2::zero(), }; diff --git a/src/backend/curses/mod.rs b/src/backend/curses/mod.rs index 13fb8bf..55b95b8 100644 --- a/src/backend/curses/mod.rs +++ b/src/backend/curses/mod.rs @@ -3,8 +3,6 @@ //! Requires either of `ncurses-backend` or `pancurses-backend`. #![cfg(any(feature = "ncurses-backend", feature = "pancurses-backend"))] -use hashbrown::HashMap; - use crate::event::{Event, Key}; use crate::theme::{BaseColor, Color, ColorPair}; use maplit::hashmap; @@ -15,6 +13,9 @@ pub mod n; #[cfg(feature = "pancurses-backend")] pub mod pan; +// Use AHash instead of the slower SipHash +type HashMap = std::collections::HashMap; + fn split_i32(code: i32) -> Vec { (0..4).map(|i| ((code >> (8 * i)) & 0xFF) as u8).collect() } diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index 5a2a784..e8bf23f 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -2,7 +2,6 @@ use log::{debug, warn}; use ncurses; -use hashbrown::HashMap; use std::cell::{Cell, RefCell}; use std::ffi::CString; use std::fs::File; @@ -20,6 +19,9 @@ use crate::vec::Vec2; use self::super::split_i32; use self::ncurses::mmask_t; +// Use AHash instead of the slower SipHash +type HashMap = std::collections::HashMap; + /// Backend using ncurses. pub struct Backend { current_style: Cell, @@ -117,7 +119,7 @@ impl Backend { let c = Backend { current_style: Cell::new(ColorPair::from_256colors(0, 0)), - pairs: RefCell::new(HashMap::new()), + pairs: RefCell::new(HashMap::default()), key_codes: initialize_keymap(), last_mouse_button: None, input_buffer: None, @@ -458,7 +460,8 @@ where fn initialize_keymap() -> HashMap { // First, define the static mappings. - let mut map = HashMap::new(); + let mut map = HashMap::default(); + // Value sent by ncurses when nothing happens map.insert(-1, Event::Refresh); diff --git a/src/backend/curses/pan.rs b/src/backend/curses/pan.rs index fd4db59..11decff 100644 --- a/src/backend/curses/pan.rs +++ b/src/backend/curses/pan.rs @@ -2,7 +2,6 @@ use log::{debug, warn}; use pancurses; -use hashbrown::HashMap; use std::cell::{Cell, RefCell}; use std::io::{stdout, Write}; @@ -14,6 +13,9 @@ use crate::vec::Vec2; use self::pancurses::mmask_t; use super::split_i32; +// Use AHash instead of the slower SipHash +type HashMap = std::collections::HashMap; + /// Backend using pancurses. pub struct Backend { // Used @@ -75,7 +77,7 @@ impl Backend { let c = Backend { current_style: Cell::new(ColorPair::from_256colors(0, 0)), - pairs: RefCell::new(HashMap::new()), + pairs: RefCell::new(HashMap::default()), key_codes: initialize_keymap(), last_mouse_button: None, input_buffer: None, @@ -530,7 +532,7 @@ fn get_mouse_button(bare_event: mmask_t) -> MouseButton { } fn initialize_keymap() -> HashMap { - let mut map = HashMap::new(); + let mut map = HashMap::default(); super::fill_key_codes(&mut map, pancurses::keyname); diff --git a/src/cursive.rs b/src/cursive.rs index ab0353c..a1b7ae4 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -1,4 +1,3 @@ -use hashbrown::HashMap; use std::any::Any; use std::num::NonZeroU32; use std::path::Path; @@ -20,6 +19,9 @@ static DEBUG_VIEW_ID: &str = "_cursive_debug_view"; // How long we wait between two empty input polls const INPUT_POLL_DELAY_MS: u64 = 30; +// Use AHash instead of the slower SipHash +type HashMap = std::collections::HashMap; + /// Central part of the cursive library. /// /// It initializes ncurses on creation and cleans up on drop. @@ -137,7 +139,7 @@ impl Cursive { theme, screens: vec![views::StackView::new()], last_sizes: Vec::new(), - global_callbacks: HashMap::new(), + global_callbacks: HashMap::default(), menubar: views::Menubar::new(), active_screen: 0, running: true, diff --git a/src/theme/palette.rs b/src/theme/palette.rs index d1bb254..858b68d 100644 --- a/src/theme/palette.rs +++ b/src/theme/palette.rs @@ -3,9 +3,11 @@ use enum_map::{enum_map, Enum, EnumMap}; use log::warn; use toml; -use hashbrown::HashMap; use std::ops::{Index, IndexMut}; +// Use AHash instead of the slower SipHash +type HashMap = std::collections::HashMap; + /// Color configuration for the application. /// /// Assign each color role an actual color. @@ -165,7 +167,7 @@ impl Default for Palette { Highlight => Dark(Red), HighlightInactive => Dark(Blue), }, - custom: HashMap::new(), + custom: HashMap::default(), } } }