diff options
author | komuhangi <51232461+jahielkomu@users.noreply.github.com> | 2024-04-04 12:33:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-04 09:33:30 +0000 |
commit | df457c43c8f78d18e4e6fbc19910e35f82249b63 (patch) | |
tree | dc0327b34a2836be9d58d05bc260638050e8cbd3 /components/script/dom | |
parent | 62a916ce5c7e3de2c33b52c79a57b1f739c420f5 (diff) | |
download | servo-df457c43c8f78d18e4e6fbc19910e35f82249b63.tar.gz servo-df457c43c8f78d18e4e6fbc19910e35f82249b63.zip |
Fixed some clippy warning by adding default implementations (#31989)
* Fixed some clippy warning by adding default implementations
* Updated PR that adds default implementation of structs
* Clean up and extend `Default` implementations
---------
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/htmlmediaelement.rs | 4 | ||||
-rw-r--r-- | components/script/dom/identityhub.rs | 40 | ||||
-rw-r--r-- | components/script/dom/node.rs | 13 | ||||
-rw-r--r-- | components/script/dom/range.rs | 12 | ||||
-rw-r--r-- | components/script/dom/serviceworkerglobalscope.rs | 2 | ||||
-rw-r--r-- | components/script/dom/timeranges.rs | 6 |
6 files changed, 17 insertions, 60 deletions
diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index 54a27e7f4b4..447e3fd40f1 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -445,7 +445,7 @@ impl HTMLMediaElement { seeking: Cell::new(false), resource_url: DomRefCell::new(None), blob_url: DomRefCell::new(None), - played: DomRefCell::new(TimeRangesContainer::new()), + played: DomRefCell::new(TimeRangesContainer::default()), audio_tracks_list: Default::default(), video_tracks_list: Default::default(), text_tracks_list: Default::default(), @@ -2346,7 +2346,7 @@ impl HTMLMediaElementMethods for HTMLMediaElement { // https://html.spec.whatwg.org/multipage/#dom-media-buffered fn Buffered(&self) -> DomRoot<TimeRanges> { - let mut buffered = TimeRangesContainer::new(); + let mut buffered = TimeRangesContainer::default(); if let Some(ref player) = *self.player.borrow() { if let Ok(ranges) = player.lock().unwrap().buffered() { for range in ranges { diff --git a/components/script/dom/identityhub.rs b/components/script/dom/identityhub.rs index 19890d56025..a4296f9ee4b 100644 --- a/components/script/dom/identityhub.rs +++ b/components/script/dom/identityhub.rs @@ -11,7 +11,7 @@ use webgpu::wgpu::id::{ use webgpu::wgpu::identity::IdentityManager; use webgpu::wgt::Backend; -#[derive(Debug)] +#[derive(Debug, Default)] pub struct IdentityHub { adapters: IdentityManager, devices: IdentityManager, @@ -29,28 +29,7 @@ pub struct IdentityHub { render_bundles: IdentityManager, } -impl IdentityHub { - fn new() -> Self { - IdentityHub { - adapters: IdentityManager::default(), - devices: IdentityManager::default(), - buffers: IdentityManager::default(), - bind_groups: IdentityManager::default(), - bind_group_layouts: IdentityManager::default(), - compute_pipelines: IdentityManager::default(), - pipeline_layouts: IdentityManager::default(), - shader_modules: IdentityManager::default(), - command_encoders: IdentityManager::default(), - textures: IdentityManager::default(), - texture_views: IdentityManager::default(), - samplers: IdentityManager::default(), - render_pipelines: IdentityManager::default(), - render_bundles: IdentityManager::default(), - } - } -} - -#[derive(Debug)] +#[derive(Debug, Default)] pub struct Identities { _surface: IdentityManager, #[cfg(any(target_os = "linux", target_os = "windows"))] @@ -65,21 +44,6 @@ pub struct Identities { } impl Identities { - pub fn new() -> Self { - Identities { - _surface: IdentityManager::default(), - #[cfg(any(target_os = "linux", target_os = "windows"))] - vk_hub: IdentityHub::new(), - #[cfg(target_os = "windows")] - dx12_hub: IdentityHub::new(), - #[cfg(target_os = "windows")] - dx11_hub: IdentityHub::new(), - #[cfg(any(target_os = "ios", target_os = "macos"))] - metal_hub: IdentityHub::new(), - dummy_hub: IdentityHub::new(), - } - } - fn select(&mut self, backend: Backend) -> &mut IdentityHub { match backend { #[cfg(any(target_os = "linux", target_os = "windows"))] diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index fa5930461bd..f37f51562e2 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -214,12 +214,6 @@ bitflags! { } } -impl NodeFlags { - pub fn new() -> NodeFlags { - NodeFlags::empty() - } -} - /// suppress observers flag /// <https://dom.spec.whatwg.org/#concept-node-insert> /// <https://dom.spec.whatwg.org/#concept-node-remove> @@ -1816,15 +1810,12 @@ impl Node { } pub fn new_inherited(doc: &Document) -> Node { - Node::new_(NodeFlags::new(), Some(doc)) + Node::new_(NodeFlags::empty(), Some(doc)) } #[allow(crown::unrooted_must_root)] pub fn new_document_node() -> Node { - Node::new_( - NodeFlags::new() | NodeFlags::IS_IN_DOC | NodeFlags::IS_CONNECTED, - None, - ) + Node::new_(NodeFlags::IS_IN_DOC | NodeFlags::IS_CONNECTED, None) } #[allow(crown::unrooted_must_root)] diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs index 0cf64e264d0..fa7d14795d3 100644 --- a/components/script/dom/range.rs +++ b/components/script/dom/range.rs @@ -1082,13 +1082,19 @@ pub struct WeakRangeVec { cell: UnsafeCell<WeakRefVec<Range>>, } +impl Default for WeakRangeVec { + fn default() -> Self { + WeakRangeVec { + cell: UnsafeCell::new(WeakRefVec::new()), + } + } +} + #[allow(unsafe_code)] impl WeakRangeVec { /// Create a new vector of weak references. pub fn new() -> Self { - WeakRangeVec { - cell: UnsafeCell::new(WeakRefVec::new()), - } + Self::default() } /// Whether that vector of ranges is empty. diff --git a/components/script/dom/serviceworkerglobalscope.rs b/components/script/dom/serviceworkerglobalscope.rs index e0f0ef21d1b..07faf3da3c9 100644 --- a/components/script/dom/serviceworkerglobalscope.rs +++ b/components/script/dom/serviceworkerglobalscope.rs @@ -242,7 +242,7 @@ impl ServiceWorkerGlobalScope { runtime, from_devtools_receiver, closing, - Arc::new(Mutex::new(Identities::new())), + Arc::new(Mutex::new(Identities::default())), ), task_queue: TaskQueue::new(receiver, own_sender.clone()), own_sender, diff --git a/components/script/dom/timeranges.rs b/components/script/dom/timeranges.rs index 21476f3fcd3..4f02330478d 100644 --- a/components/script/dom/timeranges.rs +++ b/components/script/dom/timeranges.rs @@ -56,16 +56,12 @@ pub enum TimeRangesError { OutOfRange, } -#[derive(Clone, Debug, JSTraceable, MallocSizeOf)] +#[derive(Clone, Debug, Default, JSTraceable, MallocSizeOf)] pub struct TimeRangesContainer { ranges: Vec<TimeRange>, } impl TimeRangesContainer { - pub fn new() -> Self { - Self { ranges: Vec::new() } - } - pub fn len(&self) -> u32 { self.ranges.len() as u32 } |