Replace hashbrown with std+ahash

This commit is contained in:
Alexandre Bury 2019-09-09 12:51:20 -07:00
parent 4623e40dab
commit 565c64c528
7 changed files with 28 additions and 15 deletions

View File

@ -35,8 +35,8 @@ term_size = { version = "0.3.1", optional = true }
crossbeam-channel = "0.3.9" crossbeam-channel = "0.3.9"
lazy_static = "1.3.0" lazy_static = "1.3.0"
chrono = "0.4.7" chrono = "0.4.7"
hashbrown = "0.5.0"
cfg-if = "0.1.9" cfg-if = "0.1.9"
ahash = "0.2.12"
[dependencies.num] [dependencies.num]
default-features = false default-features = false

View File

@ -5,7 +5,7 @@
use bear_lib_terminal; use bear_lib_terminal;
use hashbrown::HashSet; use std::collections::HashSet;
use self::bear_lib_terminal::geometry::Size; use self::bear_lib_terminal::geometry::Size;
use self::bear_lib_terminal::terminal::{ 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::theme::{BaseColor, Color, ColorPair, Effect};
use crate::vec::Vec2; use crate::vec::Vec2;
// Use AHash instead of the slower SipHash
type HashMap<K, V> = std::collections::HashMap<K, V, ahash::ABuildHasher>;
enum ColorRole { enum ColorRole {
Foreground, Foreground,
Background, Background,
@ -47,7 +50,7 @@ impl Backend {
]); ]);
let c = Backend { let c = Backend {
buttons_pressed: HashSet::new(), buttons_pressed: HashSet::default(),
mouse_position: Vec2::zero(), mouse_position: Vec2::zero(),
}; };

View File

@ -3,8 +3,6 @@
//! Requires either of `ncurses-backend` or `pancurses-backend`. //! Requires either of `ncurses-backend` or `pancurses-backend`.
#![cfg(any(feature = "ncurses-backend", feature = "pancurses-backend"))] #![cfg(any(feature = "ncurses-backend", feature = "pancurses-backend"))]
use hashbrown::HashMap;
use crate::event::{Event, Key}; use crate::event::{Event, Key};
use crate::theme::{BaseColor, Color, ColorPair}; use crate::theme::{BaseColor, Color, ColorPair};
use maplit::hashmap; use maplit::hashmap;
@ -15,6 +13,9 @@ pub mod n;
#[cfg(feature = "pancurses-backend")] #[cfg(feature = "pancurses-backend")]
pub mod pan; pub mod pan;
// Use AHash instead of the slower SipHash
type HashMap<K, V> = std::collections::HashMap<K, V, ahash::ABuildHasher>;
fn split_i32(code: i32) -> Vec<u8> { fn split_i32(code: i32) -> Vec<u8> {
(0..4).map(|i| ((code >> (8 * i)) & 0xFF) as u8).collect() (0..4).map(|i| ((code >> (8 * i)) & 0xFF) as u8).collect()
} }

View File

@ -2,7 +2,6 @@
use log::{debug, warn}; use log::{debug, warn};
use ncurses; use ncurses;
use hashbrown::HashMap;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::ffi::CString; use std::ffi::CString;
use std::fs::File; use std::fs::File;
@ -20,6 +19,9 @@ use crate::vec::Vec2;
use self::super::split_i32; use self::super::split_i32;
use self::ncurses::mmask_t; use self::ncurses::mmask_t;
// Use AHash instead of the slower SipHash
type HashMap<K, V> = std::collections::HashMap<K, V, ahash::ABuildHasher>;
/// Backend using ncurses. /// Backend using ncurses.
pub struct Backend { pub struct Backend {
current_style: Cell<ColorPair>, current_style: Cell<ColorPair>,
@ -117,7 +119,7 @@ impl Backend {
let c = Backend { let c = Backend {
current_style: Cell::new(ColorPair::from_256colors(0, 0)), current_style: Cell::new(ColorPair::from_256colors(0, 0)),
pairs: RefCell::new(HashMap::new()), pairs: RefCell::new(HashMap::default()),
key_codes: initialize_keymap(), key_codes: initialize_keymap(),
last_mouse_button: None, last_mouse_button: None,
input_buffer: None, input_buffer: None,
@ -458,7 +460,8 @@ where
fn initialize_keymap() -> HashMap<i32, Event> { fn initialize_keymap() -> HashMap<i32, Event> {
// First, define the static mappings. // First, define the static mappings.
let mut map = HashMap::new(); let mut map = HashMap::default();
// Value sent by ncurses when nothing happens // Value sent by ncurses when nothing happens
map.insert(-1, Event::Refresh); map.insert(-1, Event::Refresh);

View File

@ -2,7 +2,6 @@
use log::{debug, warn}; use log::{debug, warn};
use pancurses; use pancurses;
use hashbrown::HashMap;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::io::{stdout, Write}; use std::io::{stdout, Write};
@ -14,6 +13,9 @@ use crate::vec::Vec2;
use self::pancurses::mmask_t; use self::pancurses::mmask_t;
use super::split_i32; use super::split_i32;
// Use AHash instead of the slower SipHash
type HashMap<K, V> = std::collections::HashMap<K, V, ahash::ABuildHasher>;
/// Backend using pancurses. /// Backend using pancurses.
pub struct Backend { pub struct Backend {
// Used // Used
@ -75,7 +77,7 @@ impl Backend {
let c = Backend { let c = Backend {
current_style: Cell::new(ColorPair::from_256colors(0, 0)), current_style: Cell::new(ColorPair::from_256colors(0, 0)),
pairs: RefCell::new(HashMap::new()), pairs: RefCell::new(HashMap::default()),
key_codes: initialize_keymap(), key_codes: initialize_keymap(),
last_mouse_button: None, last_mouse_button: None,
input_buffer: None, input_buffer: None,
@ -530,7 +532,7 @@ fn get_mouse_button(bare_event: mmask_t) -> MouseButton {
} }
fn initialize_keymap() -> HashMap<i32, Event> { fn initialize_keymap() -> HashMap<i32, Event> {
let mut map = HashMap::new(); let mut map = HashMap::default();
super::fill_key_codes(&mut map, pancurses::keyname); super::fill_key_codes(&mut map, pancurses::keyname);

View File

@ -1,4 +1,3 @@
use hashbrown::HashMap;
use std::any::Any; use std::any::Any;
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::path::Path; 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 // How long we wait between two empty input polls
const INPUT_POLL_DELAY_MS: u64 = 30; const INPUT_POLL_DELAY_MS: u64 = 30;
// Use AHash instead of the slower SipHash
type HashMap<K, V> = std::collections::HashMap<K, V, ahash::ABuildHasher>;
/// Central part of the cursive library. /// Central part of the cursive library.
/// ///
/// It initializes ncurses on creation and cleans up on drop. /// It initializes ncurses on creation and cleans up on drop.
@ -137,7 +139,7 @@ impl Cursive {
theme, theme,
screens: vec![views::StackView::new()], screens: vec![views::StackView::new()],
last_sizes: Vec::new(), last_sizes: Vec::new(),
global_callbacks: HashMap::new(), global_callbacks: HashMap::default(),
menubar: views::Menubar::new(), menubar: views::Menubar::new(),
active_screen: 0, active_screen: 0,
running: true, running: true,

View File

@ -3,9 +3,11 @@ use enum_map::{enum_map, Enum, EnumMap};
use log::warn; use log::warn;
use toml; use toml;
use hashbrown::HashMap;
use std::ops::{Index, IndexMut}; use std::ops::{Index, IndexMut};
// Use AHash instead of the slower SipHash
type HashMap<K, V> = std::collections::HashMap<K, V, ahash::ABuildHasher>;
/// Color configuration for the application. /// Color configuration for the application.
/// ///
/// Assign each color role an actual color. /// Assign each color role an actual color.
@ -165,7 +167,7 @@ impl Default for Palette {
Highlight => Dark(Red), Highlight => Dark(Red),
HighlightInactive => Dark(Blue), HighlightInactive => Dark(Blue),
}, },
custom: HashMap::new(), custom: HashMap::default(),
} }
} }
} }