mirror of
https://github.com/servo/servo.git
synced 2025-09-23 13:20:11 +01:00
Removed FnvHash and transformed the rest to FxHashmap (#39233)
This should be the final PR for the Hash Function series that is trivial. Of note: I decided to transform `HashMapTracedValues<Atom,..>` to use FxBuildHasher. This is likely not going to improve performance as Atom's already have a unique u32 that is used as the Hash but it safes a few bytes for the RandomState that is normally in the HashMap. Signed-off-by: Narfinger <Narfinger@users.noreply.github.com> Testing: Hash function changes should not change functionality, we slightly decrease the size and unit tests still work. Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This commit is contained in:
parent
726b456120
commit
84465e7768
55 changed files with 211 additions and 202 deletions
|
@ -38,9 +38,9 @@ devtools_traits = { workspace = true }
|
|||
embedder_traits = { workspace = true }
|
||||
euclid = { workspace = true }
|
||||
fonts = { path = "../fonts" }
|
||||
fnv = { workspace = true }
|
||||
ipc-channel = { workspace = true }
|
||||
keyboard-types = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
layout_api = { workspace = true }
|
||||
log = { workspace = true }
|
||||
media = { path = "../media" }
|
||||
|
|
|
@ -6,15 +6,15 @@ use std::collections::HashMap;
|
|||
|
||||
use base::id::BroadcastChannelRouterId;
|
||||
use constellation_traits::BroadcastChannelMsg;
|
||||
use fnv::FnvHashMap;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use log::warn;
|
||||
use rustc_hash::FxHashMap;
|
||||
use servo_url::ImmutableOrigin;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct BroadcastChannels {
|
||||
/// A map of broadcast routers to their IPC sender.
|
||||
routers: FnvHashMap<BroadcastChannelRouterId, IpcSender<BroadcastChannelMsg>>,
|
||||
routers: FxHashMap<BroadcastChannelRouterId, IpcSender<BroadcastChannelMsg>>,
|
||||
|
||||
/// A map of origin to a map of channel name to a list of relevant routers.
|
||||
channels: HashMap<ImmutableOrigin, HashMap<String, Vec<BroadcastChannelRouterId>>>,
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
use base::id::{BrowsingContextGroupId, BrowsingContextId, PipelineId, WebViewId};
|
||||
use embedder_traits::ViewportDetails;
|
||||
use fnv::{FnvHashMap, FnvHashSet};
|
||||
use log::warn;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
use crate::pipeline::Pipeline;
|
||||
|
||||
|
@ -70,7 +70,7 @@ pub struct BrowsingContext {
|
|||
|
||||
/// All the pipelines that have been presented or will be presented in
|
||||
/// this browsing context.
|
||||
pub pipelines: FnvHashSet<PipelineId>,
|
||||
pub pipelines: FxHashSet<PipelineId>,
|
||||
}
|
||||
|
||||
impl BrowsingContext {
|
||||
|
@ -88,7 +88,7 @@ impl BrowsingContext {
|
|||
inherited_secure_context: Option<bool>,
|
||||
throttled: bool,
|
||||
) -> BrowsingContext {
|
||||
let mut pipelines = FnvHashSet::default();
|
||||
let mut pipelines = FxHashSet::default();
|
||||
pipelines.insert(pipeline_id);
|
||||
BrowsingContext {
|
||||
bc_group_id,
|
||||
|
@ -122,12 +122,12 @@ pub struct FullyActiveBrowsingContextsIterator<'a> {
|
|||
pub stack: Vec<BrowsingContextId>,
|
||||
|
||||
/// The set of all browsing contexts.
|
||||
pub browsing_contexts: &'a FnvHashMap<BrowsingContextId, BrowsingContext>,
|
||||
pub browsing_contexts: &'a FxHashMap<BrowsingContextId, BrowsingContext>,
|
||||
|
||||
/// The set of all pipelines. We use this to find the active
|
||||
/// children of a frame, which are the iframes in the currently
|
||||
/// active document.
|
||||
pub pipelines: &'a FnvHashMap<PipelineId, Pipeline>,
|
||||
pub pipelines: &'a FxHashMap<PipelineId, Pipeline>,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for FullyActiveBrowsingContextsIterator<'a> {
|
||||
|
@ -169,12 +169,12 @@ pub struct AllBrowsingContextsIterator<'a> {
|
|||
pub stack: Vec<BrowsingContextId>,
|
||||
|
||||
/// The set of all browsing contexts.
|
||||
pub browsing_contexts: &'a FnvHashMap<BrowsingContextId, BrowsingContext>,
|
||||
pub browsing_contexts: &'a FxHashMap<BrowsingContextId, BrowsingContext>,
|
||||
|
||||
/// The set of all pipelines. We use this to find the
|
||||
/// children of a browsing context, which are the iframes in all documents
|
||||
/// in the session history.
|
||||
pub pipelines: &'a FnvHashMap<PipelineId, Pipeline>,
|
||||
pub pipelines: &'a FxHashMap<PipelineId, Pipeline>,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for AllBrowsingContextsIterator<'a> {
|
||||
|
|
|
@ -139,7 +139,6 @@ use embedder_traits::{
|
|||
};
|
||||
use euclid::Size2D;
|
||||
use euclid::default::Size2D as UntypedSize2D;
|
||||
use fnv::{FnvHashMap, FnvHashSet};
|
||||
use fonts::SystemFontServiceProxy;
|
||||
use ipc_channel::Error as IpcError;
|
||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||
|
@ -157,6 +156,7 @@ use net_traits::{
|
|||
};
|
||||
use profile_traits::mem::ProfilerMsg;
|
||||
use profile_traits::{mem, time};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use script_traits::{
|
||||
ConstellationInputEvent, DiscardBrowsingContext, DocumentActivity, ProgressiveWebMetricType,
|
||||
ScriptThreadMessage, UpdatePipelineIdReason,
|
||||
|
@ -190,7 +190,7 @@ use crate::session_history::{
|
|||
};
|
||||
use crate::webview_manager::WebViewManager;
|
||||
|
||||
type PendingApprovalNavigations = HashMap<PipelineId, (LoadData, NavigationHistoryBehavior)>;
|
||||
type PendingApprovalNavigations = FxHashMap<PipelineId, (LoadData, NavigationHistoryBehavior)>;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// The state used by MessagePortInfo to represent the various states the port can be in.
|
||||
|
@ -241,7 +241,7 @@ struct WebrenderWGPU {
|
|||
#[derive(Clone, Default)]
|
||||
struct BrowsingContextGroup {
|
||||
/// A browsing context group holds a set of top-level browsing contexts.
|
||||
top_level_browsing_context_set: FnvHashSet<WebViewId>,
|
||||
top_level_browsing_context_set: FxHashSet<WebViewId>,
|
||||
|
||||
/// The set of all event loops in this BrowsingContextGroup.
|
||||
/// We store the event loops in a map
|
||||
|
@ -385,25 +385,25 @@ pub struct Constellation<STF, SWF> {
|
|||
webrender_wgpu: WebrenderWGPU,
|
||||
|
||||
/// A map of message-port Id to info.
|
||||
message_ports: FnvHashMap<MessagePortId, MessagePortInfo>,
|
||||
message_ports: FxHashMap<MessagePortId, MessagePortInfo>,
|
||||
|
||||
/// A map of router-id to ipc-sender, to route messages to ports.
|
||||
message_port_routers: FnvHashMap<MessagePortRouterId, IpcSender<MessagePortMsg>>,
|
||||
message_port_routers: FxHashMap<MessagePortRouterId, IpcSender<MessagePortMsg>>,
|
||||
|
||||
/// Bookkeeping for BroadcastChannel functionnality.
|
||||
broadcast_channels: BroadcastChannels,
|
||||
|
||||
/// The set of all the pipelines in the browser. (See the `pipeline` module
|
||||
/// for more details.)
|
||||
pipelines: FnvHashMap<PipelineId, Pipeline>,
|
||||
pipelines: FxHashMap<PipelineId, Pipeline>,
|
||||
|
||||
/// The set of all the browsing contexts in the browser.
|
||||
browsing_contexts: FnvHashMap<BrowsingContextId, BrowsingContext>,
|
||||
browsing_contexts: FxHashMap<BrowsingContextId, BrowsingContext>,
|
||||
|
||||
/// A user agent holds a a set of browsing context groups.
|
||||
///
|
||||
/// <https://html.spec.whatwg.org/multipage/#browsing-context-group-set>
|
||||
browsing_context_group_set: FnvHashMap<BrowsingContextGroupId, BrowsingContextGroup>,
|
||||
browsing_context_group_set: FxHashMap<BrowsingContextGroupId, BrowsingContextGroup>,
|
||||
|
||||
/// The Id counter for BrowsingContextGroup.
|
||||
browsing_context_group_next_id: u32,
|
||||
|
@ -426,7 +426,7 @@ pub struct Constellation<STF, SWF> {
|
|||
webdriver_input_command_reponse_sender: Option<IpcSender<WebDriverCommandResponse>>,
|
||||
|
||||
/// Document states for loaded pipelines (used only when writing screenshots).
|
||||
document_states: FnvHashMap<PipelineId, DocumentState>,
|
||||
document_states: FxHashMap<PipelineId, DocumentState>,
|
||||
|
||||
/// Are we shutting down?
|
||||
shutting_down: bool,
|
||||
|
@ -482,7 +482,7 @@ pub struct Constellation<STF, SWF> {
|
|||
async_runtime: Box<dyn AsyncRuntime>,
|
||||
|
||||
/// When in single-process mode, join handles for script-threads.
|
||||
script_join_handles: FnvHashMap<WebViewId, JoinHandle<()>>,
|
||||
script_join_handles: FxHashMap<WebViewId, JoinHandle<()>>,
|
||||
|
||||
/// A list of URLs that can access privileged internal APIs.
|
||||
privileged_urls: Vec<ServoUrl>,
|
||||
|
@ -2120,7 +2120,7 @@ where
|
|||
|
||||
fn handle_message_port_transfer_failed(
|
||||
&mut self,
|
||||
ports: FnvHashMap<MessagePortId, PortTransferInfo>,
|
||||
ports: FxHashMap<MessagePortId, PortTransferInfo>,
|
||||
) {
|
||||
for (port_id, mut transfer_info) in ports.into_iter() {
|
||||
let entry = match self.message_ports.remove(&port_id) {
|
||||
|
@ -2202,7 +2202,7 @@ where
|
|||
router_id: MessagePortRouterId,
|
||||
ports: Vec<MessagePortId>,
|
||||
) {
|
||||
let mut response = FnvHashMap::default();
|
||||
let mut response = FxHashMap::default();
|
||||
for port_id in ports.into_iter() {
|
||||
let entry = match self.message_ports.remove(&port_id) {
|
||||
None => {
|
||||
|
@ -3785,11 +3785,10 @@ where
|
|||
webview_id: WebViewId,
|
||||
direction: TraversalDirection,
|
||||
) {
|
||||
let mut browsing_context_changes =
|
||||
FnvHashMap::<BrowsingContextId, NeedsToReload>::default();
|
||||
let mut browsing_context_changes = FxHashMap::<BrowsingContextId, NeedsToReload>::default();
|
||||
let mut pipeline_changes =
|
||||
FnvHashMap::<PipelineId, (Option<HistoryStateId>, ServoUrl)>::default();
|
||||
let mut url_to_load = FnvHashMap::<PipelineId, ServoUrl>::default();
|
||||
FxHashMap::<PipelineId, (Option<HistoryStateId>, ServoUrl)>::default();
|
||||
let mut url_to_load = FxHashMap::<PipelineId, ServoUrl>::default();
|
||||
{
|
||||
let session_history = self.get_joint_session_history(webview_id);
|
||||
match direction {
|
||||
|
@ -4792,7 +4791,7 @@ where
|
|||
};
|
||||
|
||||
let mut pipelines_to_close = vec![];
|
||||
let mut states_to_close = FnvHashMap::default();
|
||||
let mut states_to_close = FxHashMap::default();
|
||||
|
||||
let diffs_to_close = self
|
||||
.get_joint_session_history(change.webview_id)
|
||||
|
@ -5049,7 +5048,7 @@ where
|
|||
#[servo_tracing::instrument(skip_all)]
|
||||
fn handle_is_ready_to_save_image(
|
||||
&mut self,
|
||||
pipeline_states: FnvHashMap<PipelineId, Epoch>,
|
||||
pipeline_states: FxHashMap<PipelineId, Epoch>,
|
||||
) -> ReadyToSave {
|
||||
// Note that this function can panic, due to ipc-channel creation
|
||||
// failure. Avoiding this panic would require a mechanism for dealing
|
||||
|
@ -5593,7 +5592,7 @@ where
|
|||
fn handle_set_scroll_states(
|
||||
&self,
|
||||
pipeline_id: PipelineId,
|
||||
scroll_states: FnvHashMap<ExternalScrollId, LayoutVector2D>,
|
||||
scroll_states: FxHashMap<ExternalScrollId, LayoutVector2D>,
|
||||
) {
|
||||
let Some(pipeline) = self.pipelines.get(&pipeline_id) else {
|
||||
warn!("Discarding scroll offset update for unknown pipeline");
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
use base::id::{BrowsingContextId, PipelineId};
|
||||
use embedder_traits::{InputEvent, MouseLeftViewportEvent, Theme};
|
||||
use euclid::Point2D;
|
||||
use fnv::FnvHashMap;
|
||||
use log::warn;
|
||||
use rustc_hash::FxHashMap;
|
||||
use script_traits::{ConstellationInputEvent, ScriptThreadMessage};
|
||||
use style_traits::CSSPixel;
|
||||
|
||||
|
@ -63,7 +63,7 @@ impl ConstellationWebView {
|
|||
fn target_pipeline_id_for_input_event(
|
||||
&self,
|
||||
event: &ConstellationInputEvent,
|
||||
browsing_contexts: &FnvHashMap<BrowsingContextId, BrowsingContext>,
|
||||
browsing_contexts: &FxHashMap<BrowsingContextId, BrowsingContext>,
|
||||
) -> Option<PipelineId> {
|
||||
if let Some(hit_test_result) = &event.hit_test_result {
|
||||
return Some(hit_test_result.pipeline_id);
|
||||
|
@ -84,8 +84,8 @@ impl ConstellationWebView {
|
|||
pub(crate) fn forward_input_event(
|
||||
&mut self,
|
||||
event: ConstellationInputEvent,
|
||||
pipelines: &FnvHashMap<PipelineId, Pipeline>,
|
||||
browsing_contexts: &FnvHashMap<BrowsingContextId, BrowsingContext>,
|
||||
pipelines: &FxHashMap<PipelineId, Pipeline>,
|
||||
browsing_contexts: &FxHashMap<BrowsingContextId, BrowsingContext>,
|
||||
) {
|
||||
let Some(pipeline_id) = self.target_pipeline_id_for_input_event(&event, browsing_contexts)
|
||||
else {
|
||||
|
|
|
@ -2,16 +2,14 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use base::id::WebViewId;
|
||||
use fnv::FnvHashMap;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WebViewManager<WebView> {
|
||||
/// Our top-level browsing contexts. In the WebRender scene, their pipelines are the children of
|
||||
/// a single root pipeline that also applies any pinch zoom transformation.
|
||||
webviews: FnvHashMap<WebViewId, WebView>,
|
||||
webviews: FxHashMap<WebViewId, WebView>,
|
||||
|
||||
/// The order in which they were focused, latest last.
|
||||
focus_order: Vec<WebViewId>,
|
||||
|
@ -23,7 +21,7 @@ pub struct WebViewManager<WebView> {
|
|||
impl<WebView> Default for WebViewManager<WebView> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
webviews: HashMap::default(),
|
||||
webviews: FxHashMap::default(),
|
||||
focus_order: Vec::default(),
|
||||
is_focused: false,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue