Use Fx* variants of HashMap and HashSet everywhere in Zed (#7481)

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov
2024-02-07 09:45:37 +02:00
committed by GitHub
parent 7939673a7d
commit eb236302c2
27 changed files with 96 additions and 102 deletions
+13 -13
View File
@@ -23,7 +23,7 @@ use crate::{
TextSystem, View, ViewContext, Window, WindowContext, WindowHandle, WindowId,
};
use anyhow::{anyhow, Result};
use collections::{FxHashMap, FxHashSet, VecDeque};
use collections::{HashMap, HashSet, VecDeque};
use futures::{channel::oneshot, future::LocalBoxFuture, Future};
use slotmap::SlotMap;
@@ -212,24 +212,24 @@ pub struct AppContext {
pending_updates: usize,
pub(crate) actions: Rc<ActionRegistry>,
pub(crate) active_drag: Option<AnyDrag>,
pub(crate) next_frame_callbacks: FxHashMap<DisplayId, Vec<FrameCallback>>,
pub(crate) frame_consumers: FxHashMap<DisplayId, Task<()>>,
pub(crate) next_frame_callbacks: HashMap<DisplayId, Vec<FrameCallback>>,
pub(crate) frame_consumers: HashMap<DisplayId, Task<()>>,
pub(crate) background_executor: BackgroundExecutor,
pub(crate) foreground_executor: ForegroundExecutor,
pub(crate) svg_renderer: SvgRenderer,
asset_source: Arc<dyn AssetSource>,
pub(crate) image_cache: ImageCache,
pub(crate) text_style_stack: Vec<TextStyleRefinement>,
pub(crate) globals_by_type: FxHashMap<TypeId, Box<dyn Any>>,
pub(crate) globals_by_type: HashMap<TypeId, Box<dyn Any>>,
pub(crate) entities: EntityMap,
pub(crate) new_view_observers: SubscriberSet<TypeId, NewViewListener>,
pub(crate) windows: SlotMap<WindowId, Option<Window>>,
pub(crate) keymap: Rc<RefCell<Keymap>>,
pub(crate) global_action_listeners:
FxHashMap<TypeId, Vec<Rc<dyn Fn(&dyn Any, DispatchPhase, &mut Self)>>>,
HashMap<TypeId, Vec<Rc<dyn Fn(&dyn Any, DispatchPhase, &mut Self)>>>,
pending_effects: VecDeque<Effect>,
pub(crate) pending_notifications: FxHashSet<EntityId>,
pub(crate) pending_global_notifications: FxHashSet<TypeId>,
pub(crate) pending_notifications: HashSet<EntityId>,
pub(crate) pending_global_notifications: HashSet<TypeId>,
pub(crate) observers: SubscriberSet<EntityId, Handler>,
// TypeId is the type of the event that the listener callback expects
pub(crate) event_listeners: SubscriberSet<EntityId, (TypeId, Listener)>,
@@ -274,23 +274,23 @@ impl AppContext {
flushing_effects: false,
pending_updates: 0,
active_drag: None,
next_frame_callbacks: FxHashMap::default(),
frame_consumers: FxHashMap::default(),
next_frame_callbacks: HashMap::default(),
frame_consumers: HashMap::default(),
background_executor: executor,
foreground_executor,
svg_renderer: SvgRenderer::new(asset_source.clone()),
asset_source,
image_cache: ImageCache::new(http_client),
text_style_stack: Vec::new(),
globals_by_type: FxHashMap::default(),
globals_by_type: HashMap::default(),
entities,
new_view_observers: SubscriberSet::new(),
windows: SlotMap::with_key(),
keymap: Rc::new(RefCell::new(Keymap::default())),
global_action_listeners: FxHashMap::default(),
global_action_listeners: HashMap::default(),
pending_effects: VecDeque::new(),
pending_notifications: FxHashSet::default(),
pending_global_notifications: FxHashSet::default(),
pending_notifications: HashSet::default(),
pending_global_notifications: HashSet::default(),
observers: SubscriberSet::new(),
event_listeners: SubscriberSet::new(),
release_listeners: SubscriberSet::new(),
+7 -7
View File
@@ -53,7 +53,7 @@ use crate::{
Action, ActionRegistry, DispatchPhase, ElementContext, EntityId, FocusId, KeyBinding,
KeyContext, Keymap, KeymatchResult, Keystroke, KeystrokeMatcher, WindowContext,
};
use collections::FxHashMap;
use collections::HashMap;
use smallvec::{smallvec, SmallVec};
use std::{
any::{Any, TypeId},
@@ -69,9 +69,9 @@ pub(crate) struct DispatchTree {
node_stack: Vec<DispatchNodeId>,
pub(crate) context_stack: Vec<KeyContext>,
nodes: Vec<DispatchNode>,
focusable_node_ids: FxHashMap<FocusId, DispatchNodeId>,
view_node_ids: FxHashMap<EntityId, DispatchNodeId>,
keystroke_matchers: FxHashMap<SmallVec<[KeyContext; 4]>, KeystrokeMatcher>,
focusable_node_ids: HashMap<FocusId, DispatchNodeId>,
view_node_ids: HashMap<EntityId, DispatchNodeId>,
keystroke_matchers: HashMap<SmallVec<[KeyContext; 4]>, KeystrokeMatcher>,
keymap: Rc<RefCell<Keymap>>,
action_registry: Rc<ActionRegistry>,
}
@@ -100,9 +100,9 @@ impl DispatchTree {
node_stack: Vec::new(),
context_stack: Vec::new(),
nodes: Vec::new(),
focusable_node_ids: FxHashMap::default(),
view_node_ids: FxHashMap::default(),
keystroke_matchers: FxHashMap::default(),
focusable_node_ids: HashMap::default(),
view_node_ids: HashMap::default(),
keystroke_matchers: HashMap::default(),
keymap,
action_registry,
}
+2 -5
View File
@@ -7,12 +7,9 @@ pub use context::*;
pub(crate) use matcher::*;
use crate::{Action, Keystroke, NoAction};
use collections::HashSet;
use collections::{HashMap, HashSet};
use smallvec::SmallVec;
use std::{
any::{Any, TypeId},
collections::HashMap,
};
use std::any::{Any, TypeId};
/// An opaque identifier of which version of the keymap is currently active.
/// The keymap's version is changed whenever bindings are added or removed.
+2 -2
View File
@@ -3,7 +3,7 @@ use crate::{
Point, Size,
};
use anyhow::Result;
use collections::FxHashMap;
use collections::HashMap;
use derive_more::{Deref, DerefMut};
use etagere::BucketedAtlasAllocator;
use metal::Device;
@@ -53,7 +53,7 @@ struct MetalAtlasState {
monochrome_textures: Vec<MetalAtlasTexture>,
polychrome_textures: Vec<MetalAtlasTexture>,
path_textures: Vec<MetalAtlasTexture>,
tiles_by_key: FxHashMap<AtlasKey, AtlasTile>,
tiles_by_key: HashMap<AtlasKey, AtlasTile>,
}
impl PlatformAtlas for MetalAtlas {
+2 -2
View File
@@ -2,7 +2,7 @@ use crate::{
point, AtlasTextureId, AtlasTile, Bounds, ContentMask, Corners, Edges, EntityId, Hsla, Pixels,
Point, ScaledPixels, StackingOrder,
};
use collections::{BTreeMap, FxHashSet};
use collections::{BTreeMap, HashSet};
use std::{fmt::Debug, iter::Peekable, slice};
// Exported to metal
@@ -159,7 +159,7 @@ impl Scene {
layer_id
}
pub fn reuse_views(&mut self, views: &FxHashSet<EntityId>, prev_scene: &mut Self) {
pub fn reuse_views(&mut self, views: &HashSet<EntityId>, prev_scene: &mut Self) {
for shadow in prev_scene.shadows.drain(..) {
if views.contains(&shadow.view_id.into()) {
let order = &prev_scene.orders_by_layer[&shadow.layer_id];
+11 -11
View File
@@ -2,7 +2,7 @@ use crate::{
AbsoluteLength, Bounds, DefiniteLength, Edges, Length, Pixels, Point, Size, Style,
WindowContext,
};
use collections::{FxHashMap, FxHashSet};
use collections::{HashMap, HashSet};
use smallvec::SmallVec;
use std::fmt::Debug;
use taffy::{
@@ -17,11 +17,11 @@ type NodeMeasureFn =
pub struct TaffyLayoutEngine {
taffy: Taffy,
styles: FxHashMap<LayoutId, Style>,
children_to_parents: FxHashMap<LayoutId, LayoutId>,
absolute_layout_bounds: FxHashMap<LayoutId, Bounds<Pixels>>,
computed_layouts: FxHashSet<LayoutId>,
nodes_to_measure: FxHashMap<LayoutId, NodeMeasureFn>,
styles: HashMap<LayoutId, Style>,
children_to_parents: HashMap<LayoutId, LayoutId>,
absolute_layout_bounds: HashMap<LayoutId, Bounds<Pixels>>,
computed_layouts: HashSet<LayoutId>,
nodes_to_measure: HashMap<LayoutId, NodeMeasureFn>,
}
static EXPECT_MESSAGE: &str = "we should avoid taffy layout errors by construction if possible";
@@ -30,11 +30,11 @@ impl TaffyLayoutEngine {
pub fn new() -> Self {
TaffyLayoutEngine {
taffy: Taffy::new(),
styles: FxHashMap::default(),
children_to_parents: FxHashMap::default(),
absolute_layout_bounds: FxHashMap::default(),
computed_layouts: FxHashSet::default(),
nodes_to_measure: FxHashMap::default(),
styles: HashMap::default(),
children_to_parents: HashMap::default(),
absolute_layout_bounds: HashMap::default(),
computed_layouts: HashSet::default(),
nodes_to_measure: HashMap::default(),
}
}
+6 -6
View File
@@ -13,7 +13,7 @@ use crate::{
SharedString, Size, UnderlineStyle,
};
use anyhow::anyhow;
use collections::{BTreeSet, FxHashMap, FxHashSet};
use collections::{BTreeSet, HashMap, HashSet};
use core::fmt;
use derive_more::Deref;
use itertools::Itertools;
@@ -42,10 +42,10 @@ pub(crate) const SUBPIXEL_VARIANTS: u8 = 4;
/// The GPUI text rendering sub system.
pub struct TextSystem {
platform_text_system: Arc<dyn PlatformTextSystem>,
font_ids_by_font: RwLock<FxHashMap<Font, Result<FontId>>>,
font_metrics: RwLock<FxHashMap<FontId, FontMetrics>>,
raster_bounds: RwLock<FxHashMap<RenderGlyphParams, Bounds<DevicePixels>>>,
wrapper_pool: Mutex<FxHashMap<FontIdWithSize, Vec<LineWrapper>>>,
font_ids_by_font: RwLock<HashMap<Font, Result<FontId>>>,
font_metrics: RwLock<HashMap<FontId, FontMetrics>>,
raster_bounds: RwLock<HashMap<RenderGlyphParams, Bounds<DevicePixels>>>,
wrapper_pool: Mutex<HashMap<FontIdWithSize, Vec<LineWrapper>>>,
font_runs_pool: Mutex<Vec<Vec<FontRun>>>,
fallback_font_stack: SmallVec<[Font; 2]>,
}
@@ -447,7 +447,7 @@ impl WindowTextSystem {
Ok(lines)
}
pub(crate) fn finish_frame(&self, reused_views: &FxHashSet<EntityId>) {
pub(crate) fn finish_frame(&self, reused_views: &HashSet<EntityId>) {
self.line_layout_cache.finish_frame(reused_views)
}
+6 -6
View File
@@ -1,5 +1,5 @@
use crate::{px, EntityId, FontId, GlyphId, Pixels, PlatformTextSystem, Point, Size};
use collections::{FxHashMap, FxHashSet};
use collections::{HashMap, HashSet};
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
use smallvec::SmallVec;
use std::{
@@ -277,10 +277,10 @@ impl WrappedLineLayout {
pub(crate) struct LineLayoutCache {
view_stack: Mutex<Vec<EntityId>>,
previous_frame: Mutex<FxHashMap<CacheKey, Arc<LineLayout>>>,
current_frame: RwLock<FxHashMap<CacheKey, Arc<LineLayout>>>,
previous_frame_wrapped: Mutex<FxHashMap<CacheKey, Arc<WrappedLineLayout>>>,
current_frame_wrapped: RwLock<FxHashMap<CacheKey, Arc<WrappedLineLayout>>>,
previous_frame: Mutex<HashMap<CacheKey, Arc<LineLayout>>>,
current_frame: RwLock<HashMap<CacheKey, Arc<LineLayout>>>,
previous_frame_wrapped: Mutex<HashMap<CacheKey, Arc<WrappedLineLayout>>>,
current_frame_wrapped: RwLock<HashMap<CacheKey, Arc<WrappedLineLayout>>>,
platform_text_system: Arc<dyn PlatformTextSystem>,
}
@@ -296,7 +296,7 @@ impl LineLayoutCache {
}
}
pub fn finish_frame(&self, reused_views: &FxHashSet<EntityId>) {
pub fn finish_frame(&self, reused_views: &HashSet<EntityId>) {
debug_assert_eq!(self.view_stack.lock().len(), 0);
let mut prev_frame = self.previous_frame.lock();
+3 -3
View File
@@ -10,7 +10,7 @@ use crate::{
WindowOptions, WindowTextSystem,
};
use anyhow::{anyhow, Context as _, Result};
use collections::FxHashSet;
use collections::HashSet;
use derive_more::{Deref, DerefMut};
use futures::{
channel::{mpsc, oneshot},
@@ -259,7 +259,7 @@ pub struct Window {
pub(crate) element_id_stack: GlobalElementId,
pub(crate) rendered_frame: Frame,
pub(crate) next_frame: Frame,
pub(crate) dirty_views: FxHashSet<EntityId>,
pub(crate) dirty_views: HashSet<EntityId>,
pub(crate) focus_handles: Arc<RwLock<SlotMap<FocusId, AtomicUsize>>>,
focus_listeners: SubscriberSet<(), AnyWindowFocusListener>,
focus_lost_listeners: SubscriberSet<(), AnyObserver>,
@@ -428,7 +428,7 @@ impl Window {
element_id_stack: GlobalElementId::default(),
rendered_frame: Frame::new(DispatchTree::new(cx.keymap.clone(), cx.actions.clone())),
next_frame: Frame::new(DispatchTree::new(cx.keymap.clone(), cx.actions.clone())),
dirty_views: FxHashSet::default(),
dirty_views: HashSet::default(),
focus_handles: Arc::new(RwLock::new(SlotMap::with_key())),
focus_listeners: SubscriberSet::new(),
focus_lost_listeners: SubscriberSet::new(),
+11 -11
View File
@@ -21,7 +21,7 @@ use std::{
};
use anyhow::Result;
use collections::{FxHashMap, FxHashSet};
use collections::{HashMap, HashSet};
use derive_more::{Deref, DerefMut};
use media::core_video::CVImageBuffer;
use smallvec::SmallVec;
@@ -53,8 +53,8 @@ pub(crate) struct TooltipRequest {
pub(crate) struct Frame {
pub(crate) focus: Option<FocusId>,
pub(crate) window_active: bool,
pub(crate) element_states: FxHashMap<GlobalElementId, ElementStateBox>,
pub(crate) mouse_listeners: FxHashMap<TypeId, Vec<(StackingOrder, EntityId, AnyMouseListener)>>,
pub(crate) element_states: HashMap<GlobalElementId, ElementStateBox>,
pub(crate) mouse_listeners: HashMap<TypeId, Vec<(StackingOrder, EntityId, AnyMouseListener)>>,
pub(crate) dispatch_tree: DispatchTree,
pub(crate) scene: Scene,
pub(crate) depth_map: Vec<(StackingOrder, EntityId, Bounds<Pixels>)>,
@@ -65,13 +65,13 @@ pub(crate) struct Frame {
pub(crate) element_offset_stack: Vec<Point<Pixels>>,
pub(crate) requested_input_handler: Option<RequestedInputHandler>,
pub(crate) tooltip_request: Option<TooltipRequest>,
pub(crate) cursor_styles: FxHashMap<EntityId, CursorStyle>,
pub(crate) cursor_styles: HashMap<EntityId, CursorStyle>,
pub(crate) requested_cursor_style: Option<CursorStyle>,
pub(crate) view_stack: Vec<EntityId>,
pub(crate) reused_views: FxHashSet<EntityId>,
pub(crate) reused_views: HashSet<EntityId>,
#[cfg(any(test, feature = "test-support"))]
pub(crate) debug_bounds: collections::FxHashMap<String, Bounds<Pixels>>,
pub(crate) debug_bounds: collections::HashMap<String, Bounds<Pixels>>,
}
impl Frame {
@@ -79,8 +79,8 @@ impl Frame {
Frame {
focus: None,
window_active: false,
element_states: FxHashMap::default(),
mouse_listeners: FxHashMap::default(),
element_states: HashMap::default(),
mouse_listeners: HashMap::default(),
dispatch_tree,
scene: Scene::default(),
depth_map: Vec::new(),
@@ -91,13 +91,13 @@ impl Frame {
element_offset_stack: Vec::new(),
requested_input_handler: None,
tooltip_request: None,
cursor_styles: FxHashMap::default(),
cursor_styles: HashMap::default(),
requested_cursor_style: None,
view_stack: Vec::new(),
reused_views: FxHashSet::default(),
reused_views: HashSet::default(),
#[cfg(any(test, feature = "test-support"))]
debug_bounds: FxHashMap::default(),
debug_bounds: HashMap::default(),
}
}