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 = [
|
dependencies = [
|
||||||
"getrandom",
|
"getrandom",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"serde",
|
||||||
"version_check",
|
"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};
|
use crate::{any, area, window, Id, IdMap, InputState, LayerId, Pos2, Rect, Style};
|
||||||
|
|
||||||
|
@ -464,15 +464,15 @@ pub struct Areas {
|
||||||
areas: IdMap<area::State>,
|
areas: IdMap<area::State>,
|
||||||
/// Back-to-front. Top is last.
|
/// Back-to-front. Top is last.
|
||||||
order: Vec<LayerId>,
|
order: Vec<LayerId>,
|
||||||
visible_last_frame: HashSet<LayerId>,
|
visible_last_frame: AHashSet<LayerId>,
|
||||||
visible_current_frame: HashSet<LayerId>,
|
visible_current_frame: AHashSet<LayerId>,
|
||||||
|
|
||||||
/// When an area want to be on top, it is put in here.
|
/// 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.
|
/// 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.
|
/// 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,
|
/// 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.
|
/// 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 {
|
impl Areas {
|
||||||
|
@ -524,7 +524,7 @@ impl Areas {
|
||||||
self.visible_last_frame.contains(layer_id) || self.visible_current_frame.contains(layer_id)
|
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
|
self.visible_last_frame
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::{
|
use std::{collections::BTreeMap, string::String};
|
||||||
collections::{BTreeMap, HashSet},
|
|
||||||
string::String,
|
use epaint::ahash::AHashSet;
|
||||||
};
|
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
|
@ -167,7 +166,7 @@ impl LegendWidget {
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
config: Legend,
|
config: Legend,
|
||||||
items: &[Box<dyn PlotItem>],
|
items: &[Box<dyn PlotItem>],
|
||||||
hidden_items: &HashSet<String>,
|
hidden_items: &AHashSet<String>,
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
// Collect the legend entries. If multiple items have the same name, they share a
|
// 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.
|
// 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.
|
// 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
|
self.entries
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(_, entry)| !entry.checked)
|
.filter(|(_, entry)| !entry.checked)
|
||||||
|
|
|
@ -4,8 +4,6 @@ mod items;
|
||||||
mod legend;
|
mod legend;
|
||||||
mod transform;
|
mod transform;
|
||||||
|
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
use items::PlotItem;
|
use items::PlotItem;
|
||||||
pub use items::{
|
pub use items::{
|
||||||
Arrows, HLine, Line, LineStyle, MarkerShape, PlotImage, Points, Polygon, Text, VLine, Value,
|
Arrows, HLine, Line, LineStyle, MarkerShape, PlotImage, Points, Polygon, Text, VLine, Value,
|
||||||
|
@ -17,6 +15,7 @@ use transform::{Bounds, ScreenTransform};
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use color::Hsva;
|
use color::Hsva;
|
||||||
|
use epaint::ahash::AHashSet;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@ struct PlotMemory {
|
||||||
bounds: Bounds,
|
bounds: Bounds,
|
||||||
auto_bounds: bool,
|
auto_bounds: bool,
|
||||||
hovered_entry: Option<String>,
|
hovered_entry: Option<String>,
|
||||||
hidden_items: HashSet<String>,
|
hidden_items: AHashSet<String>,
|
||||||
min_auto_bounds: Bounds,
|
min_auto_bounds: Bounds,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,7 +349,7 @@ impl Widget for Plot {
|
||||||
bounds: min_auto_bounds,
|
bounds: min_auto_bounds,
|
||||||
auto_bounds: !min_auto_bounds.is_valid(),
|
auto_bounds: !min_auto_bounds.is_valid(),
|
||||||
hovered_entry: None,
|
hovered_entry: None,
|
||||||
hidden_items: HashSet::new(),
|
hidden_items: Default::default(),
|
||||||
min_auto_bounds,
|
min_auto_bounds,
|
||||||
})
|
})
|
||||||
.clone();
|
.clone();
|
||||||
|
|
|
@ -39,6 +39,9 @@ bytemuck = { version = "1.7.2", features = ["derive"], optional = true }
|
||||||
[features]
|
[features]
|
||||||
default = ["default_fonts", "multi_threaded"]
|
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 set, epaint will use `include_bytes!` to bundle some fonts.
|
||||||
# If you plan on specifying your own fonts you may disable this feature.
|
# If you plan on specifying your own fonts you may disable this feature.
|
||||||
default_fonts = []
|
default_fonts = []
|
||||||
|
@ -52,10 +55,7 @@ extra_asserts = ["emath/extra_asserts"]
|
||||||
mint = ["emath/mint"]
|
mint = ["emath/mint"]
|
||||||
|
|
||||||
# implement serde on most types.
|
# implement serde on most types.
|
||||||
serialize = ["serde", "emath/serde"]
|
serialize = ["serde", "ahash/serde", "emath/serde"]
|
||||||
|
|
||||||
# implement bytemuck on most types.
|
|
||||||
convert_bytemuck = ["bytemuck", "emath/bytemuck"]
|
|
||||||
|
|
||||||
single_threaded = ["atomic_refcell"]
|
single_threaded = ["atomic_refcell"]
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub struct Mutex<T>(parking_lot::Mutex<T>);
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
thread_local! {
|
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")]
|
#[cfg(feature = "multi_threaded")]
|
||||||
|
|
Loading…
Reference in a new issue