mirror of
https://github.com/servo/servo.git
synced 2025-10-01 00:59:15 +01:00
More changes to HashMap/HashSet to use fxhash (#39244)
Moved more functions to fxhash. And provide comments about the choices when necessary. Testing: Hash functions shouldn't change functionality. Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This commit is contained in:
parent
389f0d4cc2
commit
32b656adf4
6 changed files with 18 additions and 16 deletions
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::{Cell, Ref, RefCell};
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::env;
|
||||
use std::fs::create_dir_all;
|
||||
|
@ -1693,9 +1692,9 @@ struct FrameDelayer {
|
|||
/// The latest [`Epoch`] of canvas images that have been sent to WebRender. Note
|
||||
/// that this only records the `Epoch`s for canvases and only ones that are involved
|
||||
/// in "update the rendering".
|
||||
image_epochs: HashMap<ImageKey, Epoch>,
|
||||
image_epochs: FxHashMap<ImageKey, Epoch>,
|
||||
/// A map of all pending canvas images
|
||||
pending_canvas_images: HashMap<ImageKey, Epoch>,
|
||||
pending_canvas_images: FxHashMap<ImageKey, Epoch>,
|
||||
/// Whether or not we have a pending frame.
|
||||
pending_frame: bool,
|
||||
/// A list of pipelines that should be notified when we are no longer waiting for
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
* 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 std::collections::hash_map::Entry;
|
||||
use std::future::Future;
|
||||
use std::ops::Bound;
|
||||
|
@ -14,6 +13,7 @@ use log::error;
|
|||
use net_traits::filemanager_thread::RelativePos;
|
||||
use net_traits::request::Request;
|
||||
use net_traits::response::Response;
|
||||
use rustc_hash::FxHashMap;
|
||||
use servo_url::ServoUrl;
|
||||
|
||||
use crate::fetch::methods::{DoneChannel, FetchContext, RangeRequestBounds};
|
||||
|
@ -68,7 +68,7 @@ pub trait ProtocolHandler: Send + Sync {
|
|||
|
||||
#[derive(Default)]
|
||||
pub struct ProtocolRegistry {
|
||||
pub(crate) handlers: HashMap<String, Box<dyn ProtocolHandler>>, // Maps scheme -> handler
|
||||
pub(crate) handlers: FxHashMap<String, Box<dyn ProtocolHandler>>, // Maps scheme -> handler
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
@ -94,6 +94,7 @@ impl ProtocolRegistry {
|
|||
registry
|
||||
}
|
||||
|
||||
/// Do not allow users to enter an arbitrary protocol as this can lead to slowdowns.
|
||||
pub fn register(
|
||||
&mut self,
|
||||
scheme: &str,
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::collections::HashSet;
|
||||
use std::default::Default;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, LazyLock};
|
||||
|
@ -32,6 +31,7 @@ use pixels::{
|
|||
CorsStatus, ImageMetadata, PixelFormat, Snapshot, SnapshotAlphaMode, SnapshotPixelFormat,
|
||||
};
|
||||
use regex::Regex;
|
||||
use rustc_hash::FxHashSet;
|
||||
use servo_url::ServoUrl;
|
||||
use servo_url::origin::MutableOrigin;
|
||||
use style::attr::{AttrValue, LengthOrPercentageOrAuto, parse_unsigned_integer};
|
||||
|
@ -840,7 +840,8 @@ impl HTMLImageElement {
|
|||
let source_set = self.source_set.borrow();
|
||||
let len = source_set.image_sources.len();
|
||||
|
||||
let mut repeat_indices = HashSet::new();
|
||||
// Using FxHash is ok here as the indices are just 0..len
|
||||
let mut repeat_indices = FxHashSet::default();
|
||||
for outer_index in 0..len {
|
||||
if repeat_indices.contains(&outer_index) {
|
||||
continue;
|
||||
|
|
|
@ -12,6 +12,7 @@ use crossbeam_channel::Sender;
|
|||
use embedder_traits::{AnimationState, EventLoopWaker, TouchEventResult};
|
||||
use log::warn;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use rustc_hash::FxHashMap;
|
||||
use smallvec::SmallVec;
|
||||
use strum_macros::IntoStaticStr;
|
||||
use webrender_api::{DocumentId, FontVariation};
|
||||
|
@ -20,7 +21,6 @@ pub mod display_list;
|
|||
pub mod rendering_context;
|
||||
pub mod viewport_description;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use base::generic_channel::{self, GenericCallback, GenericSender};
|
||||
|
@ -426,7 +426,7 @@ pub enum WebrenderImageHandlerType {
|
|||
#[derive(Default)]
|
||||
pub struct WebrenderExternalImageRegistry {
|
||||
/// Map of all generated external images.
|
||||
external_images: HashMap<ExternalImageId, WebrenderImageHandlerType>,
|
||||
external_images: FxHashMap<ExternalImageId, WebrenderImageHandlerType>,
|
||||
/// Id generator for the next external image identifier.
|
||||
next_image_id: u64,
|
||||
}
|
||||
|
|
|
@ -14,20 +14,22 @@
|
|||
//! we don't need to make the code more complex for it. The `mach` update command makes sure that
|
||||
//! those cases are not present.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::iter::FromIterator;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use embedder_traits::resources::{self, Resource};
|
||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use rustc_hash::FxHashSet;
|
||||
use servo_url::{Host, ImmutableOrigin, ServoUrl};
|
||||
|
||||
// We can use FxHash here.
|
||||
// The list is given by publicsuffix.org so an attack is highly unlikely
|
||||
#[derive(Clone, Debug, Default, MallocSizeOf)]
|
||||
pub struct PubDomainRules {
|
||||
rules: HashSet<String>,
|
||||
wildcards: HashSet<String>,
|
||||
exceptions: HashSet<String>,
|
||||
rules: FxHashSet<String>,
|
||||
wildcards: FxHashSet<String>,
|
||||
exceptions: FxHashSet<String>,
|
||||
}
|
||||
|
||||
static PUB_DOMAINS: LazyLock<PubDomainRules> = LazyLock::new(load_pub_domains);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
* 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 std::num::NonZeroU32;
|
||||
|
||||
use canvas_traits::webgl::{
|
||||
|
@ -25,7 +24,7 @@ use crate::webgl_thread::{GLContextData, WebGLThread};
|
|||
/// Bridge between WebGL and WebXR
|
||||
pub(crate) struct WebXRBridge {
|
||||
factory_receiver: crossbeam_channel::Receiver<WebXRLayerManagerFactory<WebXRSurfman>>,
|
||||
managers: HashMap<WebXRLayerManagerId, Box<dyn WebXRLayerManagerAPI<WebXRSurfman>>>,
|
||||
managers: FxHashMap<WebXRLayerManagerId, Box<dyn WebXRLayerManagerAPI<WebXRSurfman>>>,
|
||||
next_manager_id: NonZeroU32,
|
||||
}
|
||||
|
||||
|
@ -34,7 +33,7 @@ impl WebXRBridge {
|
|||
let WebXRBridgeInit {
|
||||
factory_receiver, ..
|
||||
} = init;
|
||||
let managers = HashMap::new();
|
||||
let managers = FxHashMap::default();
|
||||
let next_manager_id = NonZeroU32::MIN;
|
||||
WebXRBridge {
|
||||
factory_receiver,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue