aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorkomuhangi <51232461+jahielkomu@users.noreply.github.com>2024-04-04 12:33:30 +0300
committerGitHub <noreply@github.com>2024-04-04 09:33:30 +0000
commitdf457c43c8f78d18e4e6fbc19910e35f82249b63 (patch)
treedc0327b34a2836be9d58d05bc260638050e8cbd3 /components/script
parent62a916ce5c7e3de2c33b52c79a57b1f739c420f5 (diff)
downloadservo-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')
-rw-r--r--components/script/dom/htmlmediaelement.rs4
-rw-r--r--components/script/dom/identityhub.rs40
-rw-r--r--components/script/dom/node.rs13
-rw-r--r--components/script/dom/range.rs12
-rw-r--r--components/script/dom/serviceworkerglobalscope.rs2
-rw-r--r--components/script/dom/timeranges.rs6
-rw-r--r--components/script/init.rs2
-rw-r--r--components/script/script_runtime.rs4
-rw-r--r--components/script/script_thread.rs4
9 files changed, 22 insertions, 65 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
}
diff --git a/components/script/init.rs b/components/script/init.rs
index 8cd93fe2aa0..badd36668bb 100644
--- a/components/script/init.rs
+++ b/components/script/init.rs
@@ -72,5 +72,5 @@ pub fn init() -> JSEngineSetup {
perform_platform_specific_initialization();
- JSEngineSetup::new()
+ JSEngineSetup::default()
}
diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs
index fc62991149b..9aac9fb9baa 100644
--- a/components/script/script_runtime.rs
+++ b/components/script/script_runtime.rs
@@ -411,8 +411,8 @@ impl Deref for Runtime {
pub struct JSEngineSetup(JSEngine);
-impl JSEngineSetup {
- pub fn new() -> Self {
+impl Default for JSEngineSetup {
+ fn default() -> Self {
let engine = JSEngine::init().unwrap();
*JS_ENGINE.lock().unwrap() = Some(engine.handle());
Self(engine)
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 60169c9ea1f..6b88a53d403 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -855,7 +855,7 @@ impl ScriptThreadFactory for ScriptThread {
}
impl ScriptThread {
- pub fn with_layout<'a, T>(
+ pub fn with_layout<T>(
pipeline_id: PipelineId,
call: impl FnOnce(&mut dyn Layout) -> T,
) -> Result<T, ()> {
@@ -1426,7 +1426,7 @@ impl ScriptThread {
node_ids: Default::default(),
is_user_interacting: Cell::new(false),
- gpu_id_hub: Arc::new(Mutex::new(Identities::new())),
+ gpu_id_hub: Arc::new(Mutex::new(Identities::default())),
webgpu_port: RefCell::new(None),
inherited_secure_context: state.inherited_secure_context,
layouts: Default::default(),