Optimization: replace HashSet uses with AHashSet
This commit is contained in:
parent
4dcdd014d6
commit
22a3a75eb5
6 changed files with 19 additions and 20 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -47,6 +47,7 @@ checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98"
|
|||
dependencies = [
|
||||
"getrandom",
|
||||
"once_cell",
|
||||
"serde",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::collections::HashSet;
|
||||
use epaint::ahash::AHashSet;
|
||||
|
||||
use crate::{any, area, window, Id, IdMap, InputState, LayerId, Pos2, Rect, Style};
|
||||
|
||||
|
@ -464,15 +464,15 @@ pub struct Areas {
|
|||
areas: IdMap<area::State>,
|
||||
/// Back-to-front. Top is last.
|
||||
order: Vec<LayerId>,
|
||||
visible_last_frame: HashSet<LayerId>,
|
||||
visible_current_frame: HashSet<LayerId>,
|
||||
visible_last_frame: AHashSet<LayerId>,
|
||||
visible_current_frame: AHashSet<LayerId>,
|
||||
|
||||
/// When an area want to be on top, it is put in here.
|
||||
/// At the end of the frame, this is used to reorder the layers.
|
||||
/// This means if several layers want to be on top, they will keep their relative order.
|
||||
/// So if you close three windows and then reopen them all in one frame,
|
||||
/// they will all be sent to the top, but keep their previous internal order.
|
||||
wants_to_be_on_top: HashSet<LayerId>,
|
||||
wants_to_be_on_top: AHashSet<LayerId>,
|
||||
}
|
||||
|
||||
impl Areas {
|
||||
|
@ -524,7 +524,7 @@ impl Areas {
|
|||
self.visible_last_frame.contains(layer_id) || self.visible_current_frame.contains(layer_id)
|
||||
}
|
||||
|
||||
pub fn visible_layer_ids(&self) -> HashSet<LayerId> {
|
||||
pub fn visible_layer_ids(&self) -> AHashSet<LayerId> {
|
||||
self.visible_last_frame
|
||||
.iter()
|
||||
.cloned()
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::{
|
||||
collections::{BTreeMap, HashSet},
|
||||
string::String,
|
||||
};
|
||||
use std::{collections::BTreeMap, string::String};
|
||||
|
||||
use epaint::ahash::AHashSet;
|
||||
|
||||
use crate::*;
|
||||
|
||||
|
@ -167,7 +166,7 @@ impl LegendWidget {
|
|||
rect: Rect,
|
||||
config: Legend,
|
||||
items: &[Box<dyn PlotItem>],
|
||||
hidden_items: &HashSet<String>,
|
||||
hidden_items: &AHashSet<String>,
|
||||
) -> Option<Self> {
|
||||
// Collect the legend entries. If multiple items have the same name, they share a
|
||||
// checkbox. If their colors don't match, we pick a neutral color for the checkbox.
|
||||
|
@ -198,7 +197,7 @@ impl LegendWidget {
|
|||
}
|
||||
|
||||
// Get the names of the hidden items.
|
||||
pub fn get_hidden_items(&self) -> HashSet<String> {
|
||||
pub fn get_hidden_items(&self) -> AHashSet<String> {
|
||||
self.entries
|
||||
.iter()
|
||||
.filter(|(_, entry)| !entry.checked)
|
||||
|
|
|
@ -4,8 +4,6 @@ mod items;
|
|||
mod legend;
|
||||
mod transform;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use items::PlotItem;
|
||||
pub use items::{
|
||||
Arrows, HLine, Line, LineStyle, MarkerShape, PlotImage, Points, Polygon, Text, VLine, Value,
|
||||
|
@ -17,6 +15,7 @@ use transform::{Bounds, ScreenTransform};
|
|||
|
||||
use crate::*;
|
||||
use color::Hsva;
|
||||
use epaint::ahash::AHashSet;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
@ -27,7 +26,7 @@ struct PlotMemory {
|
|||
bounds: Bounds,
|
||||
auto_bounds: bool,
|
||||
hovered_entry: Option<String>,
|
||||
hidden_items: HashSet<String>,
|
||||
hidden_items: AHashSet<String>,
|
||||
min_auto_bounds: Bounds,
|
||||
}
|
||||
|
||||
|
@ -350,7 +349,7 @@ impl Widget for Plot {
|
|||
bounds: min_auto_bounds,
|
||||
auto_bounds: !min_auto_bounds.is_valid(),
|
||||
hovered_entry: None,
|
||||
hidden_items: HashSet::new(),
|
||||
hidden_items: Default::default(),
|
||||
min_auto_bounds,
|
||||
})
|
||||
.clone();
|
||||
|
|
|
@ -39,6 +39,9 @@ bytemuck = { version = "1.7.2", features = ["derive"], optional = true }
|
|||
[features]
|
||||
default = ["default_fonts", "multi_threaded"]
|
||||
|
||||
# implement bytemuck on most types.
|
||||
convert_bytemuck = ["bytemuck", "emath/bytemuck"]
|
||||
|
||||
# If set, epaint will use `include_bytes!` to bundle some fonts.
|
||||
# If you plan on specifying your own fonts you may disable this feature.
|
||||
default_fonts = []
|
||||
|
@ -52,10 +55,7 @@ extra_asserts = ["emath/extra_asserts"]
|
|||
mint = ["emath/mint"]
|
||||
|
||||
# implement serde on most types.
|
||||
serialize = ["serde", "emath/serde"]
|
||||
|
||||
# implement bytemuck on most types.
|
||||
convert_bytemuck = ["bytemuck", "emath/bytemuck"]
|
||||
serialize = ["serde", "ahash/serde", "emath/serde"]
|
||||
|
||||
single_threaded = ["atomic_refcell"]
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ pub struct Mutex<T>(parking_lot::Mutex<T>);
|
|||
|
||||
#[cfg(debug_assertions)]
|
||||
thread_local! {
|
||||
static HELD_LOCKS_TLS: std::cell::RefCell<std::collections::HashSet<*const ()>> = std::cell::RefCell::new(std::collections::HashSet::new());
|
||||
static HELD_LOCKS_TLS: std::cell::RefCell<ahash::AHashSet<*const ()>> = std::cell::RefCell::new(ahash::AHashSet::new());
|
||||
}
|
||||
|
||||
#[cfg(feature = "multi_threaded")]
|
||||
|
|
Loading…
Reference in a new issue