mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
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>
This commit is contained in:
parent
62a916ce5c
commit
df457c43c8
10 changed files with 28 additions and 71 deletions
|
@ -445,7 +445,7 @@ impl HTMLMediaElement {
|
||||||
seeking: Cell::new(false),
|
seeking: Cell::new(false),
|
||||||
resource_url: DomRefCell::new(None),
|
resource_url: DomRefCell::new(None),
|
||||||
blob_url: DomRefCell::new(None),
|
blob_url: DomRefCell::new(None),
|
||||||
played: DomRefCell::new(TimeRangesContainer::new()),
|
played: DomRefCell::new(TimeRangesContainer::default()),
|
||||||
audio_tracks_list: Default::default(),
|
audio_tracks_list: Default::default(),
|
||||||
video_tracks_list: Default::default(),
|
video_tracks_list: Default::default(),
|
||||||
text_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
|
// https://html.spec.whatwg.org/multipage/#dom-media-buffered
|
||||||
fn Buffered(&self) -> DomRoot<TimeRanges> {
|
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 Some(ref player) = *self.player.borrow() {
|
||||||
if let Ok(ranges) = player.lock().unwrap().buffered() {
|
if let Ok(ranges) = player.lock().unwrap().buffered() {
|
||||||
for range in ranges {
|
for range in ranges {
|
||||||
|
|
|
@ -11,7 +11,7 @@ use webgpu::wgpu::id::{
|
||||||
use webgpu::wgpu::identity::IdentityManager;
|
use webgpu::wgpu::identity::IdentityManager;
|
||||||
use webgpu::wgt::Backend;
|
use webgpu::wgt::Backend;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub struct IdentityHub {
|
pub struct IdentityHub {
|
||||||
adapters: IdentityManager,
|
adapters: IdentityManager,
|
||||||
devices: IdentityManager,
|
devices: IdentityManager,
|
||||||
|
@ -29,28 +29,7 @@ pub struct IdentityHub {
|
||||||
render_bundles: IdentityManager,
|
render_bundles: IdentityManager,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IdentityHub {
|
#[derive(Debug, Default)]
|
||||||
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)]
|
|
||||||
pub struct Identities {
|
pub struct Identities {
|
||||||
_surface: IdentityManager,
|
_surface: IdentityManager,
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||||
|
@ -65,21 +44,6 @@ pub struct Identities {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
fn select(&mut self, backend: Backend) -> &mut IdentityHub {
|
||||||
match backend {
|
match backend {
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||||
|
|
|
@ -214,12 +214,6 @@ bitflags! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeFlags {
|
|
||||||
pub fn new() -> NodeFlags {
|
|
||||||
NodeFlags::empty()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// suppress observers flag
|
/// suppress observers flag
|
||||||
/// <https://dom.spec.whatwg.org/#concept-node-insert>
|
/// <https://dom.spec.whatwg.org/#concept-node-insert>
|
||||||
/// <https://dom.spec.whatwg.org/#concept-node-remove>
|
/// <https://dom.spec.whatwg.org/#concept-node-remove>
|
||||||
|
@ -1816,15 +1810,12 @@ impl Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_inherited(doc: &Document) -> 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)]
|
#[allow(crown::unrooted_must_root)]
|
||||||
pub fn new_document_node() -> Node {
|
pub fn new_document_node() -> Node {
|
||||||
Node::new_(
|
Node::new_(NodeFlags::IS_IN_DOC | NodeFlags::IS_CONNECTED, None)
|
||||||
NodeFlags::new() | NodeFlags::IS_IN_DOC | NodeFlags::IS_CONNECTED,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(crown::unrooted_must_root)]
|
#[allow(crown::unrooted_must_root)]
|
||||||
|
|
|
@ -1082,13 +1082,19 @@ pub struct WeakRangeVec {
|
||||||
cell: UnsafeCell<WeakRefVec<Range>>,
|
cell: UnsafeCell<WeakRefVec<Range>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for WeakRangeVec {
|
||||||
|
fn default() -> Self {
|
||||||
|
WeakRangeVec {
|
||||||
|
cell: UnsafeCell::new(WeakRefVec::new()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
impl WeakRangeVec {
|
impl WeakRangeVec {
|
||||||
/// Create a new vector of weak references.
|
/// Create a new vector of weak references.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
WeakRangeVec {
|
Self::default()
|
||||||
cell: UnsafeCell::new(WeakRefVec::new()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether that vector of ranges is empty.
|
/// Whether that vector of ranges is empty.
|
||||||
|
|
|
@ -242,7 +242,7 @@ impl ServiceWorkerGlobalScope {
|
||||||
runtime,
|
runtime,
|
||||||
from_devtools_receiver,
|
from_devtools_receiver,
|
||||||
closing,
|
closing,
|
||||||
Arc::new(Mutex::new(Identities::new())),
|
Arc::new(Mutex::new(Identities::default())),
|
||||||
),
|
),
|
||||||
task_queue: TaskQueue::new(receiver, own_sender.clone()),
|
task_queue: TaskQueue::new(receiver, own_sender.clone()),
|
||||||
own_sender,
|
own_sender,
|
||||||
|
|
|
@ -56,16 +56,12 @@ pub enum TimeRangesError {
|
||||||
OutOfRange,
|
OutOfRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, JSTraceable, MallocSizeOf)]
|
#[derive(Clone, Debug, Default, JSTraceable, MallocSizeOf)]
|
||||||
pub struct TimeRangesContainer {
|
pub struct TimeRangesContainer {
|
||||||
ranges: Vec<TimeRange>,
|
ranges: Vec<TimeRange>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TimeRangesContainer {
|
impl TimeRangesContainer {
|
||||||
pub fn new() -> Self {
|
|
||||||
Self { ranges: Vec::new() }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn len(&self) -> u32 {
|
pub fn len(&self) -> u32 {
|
||||||
self.ranges.len() as u32
|
self.ranges.len() as u32
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,5 +72,5 @@ pub fn init() -> JSEngineSetup {
|
||||||
|
|
||||||
perform_platform_specific_initialization();
|
perform_platform_specific_initialization();
|
||||||
|
|
||||||
JSEngineSetup::new()
|
JSEngineSetup::default()
|
||||||
}
|
}
|
||||||
|
|
|
@ -411,8 +411,8 @@ impl Deref for Runtime {
|
||||||
|
|
||||||
pub struct JSEngineSetup(JSEngine);
|
pub struct JSEngineSetup(JSEngine);
|
||||||
|
|
||||||
impl JSEngineSetup {
|
impl Default for JSEngineSetup {
|
||||||
pub fn new() -> Self {
|
fn default() -> Self {
|
||||||
let engine = JSEngine::init().unwrap();
|
let engine = JSEngine::init().unwrap();
|
||||||
*JS_ENGINE.lock().unwrap() = Some(engine.handle());
|
*JS_ENGINE.lock().unwrap() = Some(engine.handle());
|
||||||
Self(engine)
|
Self(engine)
|
||||||
|
|
|
@ -855,7 +855,7 @@ impl ScriptThreadFactory for ScriptThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ScriptThread {
|
impl ScriptThread {
|
||||||
pub fn with_layout<'a, T>(
|
pub fn with_layout<T>(
|
||||||
pipeline_id: PipelineId,
|
pipeline_id: PipelineId,
|
||||||
call: impl FnOnce(&mut dyn Layout) -> T,
|
call: impl FnOnce(&mut dyn Layout) -> T,
|
||||||
) -> Result<T, ()> {
|
) -> Result<T, ()> {
|
||||||
|
@ -1426,7 +1426,7 @@ impl ScriptThread {
|
||||||
|
|
||||||
node_ids: Default::default(),
|
node_ids: Default::default(),
|
||||||
is_user_interacting: Cell::new(false),
|
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),
|
webgpu_port: RefCell::new(None),
|
||||||
inherited_secure_context: state.inherited_secure_context,
|
inherited_secure_context: state.inherited_secure_context,
|
||||||
layouts: Default::default(),
|
layouts: Default::default(),
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn check(time_ranges: &TimeRangesContainer, expected: &'static str) {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn initial_state() {
|
fn initial_state() {
|
||||||
let time_ranges = TimeRangesContainer::new();
|
let time_ranges = TimeRangesContainer::default();
|
||||||
assert_eq!(time_ranges.len(), 0);
|
assert_eq!(time_ranges.len(), 0);
|
||||||
assert!(time_ranges.start(0).is_err());
|
assert!(time_ranges.start(0).is_err());
|
||||||
assert!(time_ranges.end(0).is_err());
|
assert!(time_ranges.end(0).is_err());
|
||||||
|
@ -21,13 +21,13 @@ fn initial_state() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_if_start_is_older_than_end() {
|
fn error_if_start_is_older_than_end() {
|
||||||
let mut time_ranges = TimeRangesContainer::new();
|
let mut time_ranges = TimeRangesContainer::default();
|
||||||
assert!(time_ranges.add(2., 1.).is_err());
|
assert!(time_ranges.add(2., 1.).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn single_range() {
|
fn single_range() {
|
||||||
let mut time_ranges = TimeRangesContainer::new();
|
let mut time_ranges = TimeRangesContainer::default();
|
||||||
time_ranges.add(1., 2.).unwrap();
|
time_ranges.add(1., 2.).unwrap();
|
||||||
check(&time_ranges, "[1,2)");
|
check(&time_ranges, "[1,2)");
|
||||||
assert_eq!(time_ranges.start(0).unwrap(), 1.);
|
assert_eq!(time_ranges.start(0).unwrap(), 1.);
|
||||||
|
@ -36,14 +36,14 @@ fn single_range() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_order() {
|
fn add_order() {
|
||||||
let mut time_ranges_a = TimeRangesContainer::new();
|
let mut time_ranges_a = TimeRangesContainer::default();
|
||||||
for range in vec![(0., 2.), (3., 4.), (5., 100.)].iter() {
|
for range in vec![(0., 2.), (3., 4.), (5., 100.)].iter() {
|
||||||
time_ranges_a.add(range.0, range.1).unwrap();
|
time_ranges_a.add(range.0, range.1).unwrap();
|
||||||
}
|
}
|
||||||
let expected = "[0,2), [3,4), [5,100)";
|
let expected = "[0,2), [3,4), [5,100)";
|
||||||
check(&time_ranges_a, expected);
|
check(&time_ranges_a, expected);
|
||||||
|
|
||||||
let mut time_ranges_b = TimeRangesContainer::new();
|
let mut time_ranges_b = TimeRangesContainer::default();
|
||||||
// Add the values in time_ranges_a to time_ranges_b in reverse order.
|
// Add the values in time_ranges_a to time_ranges_b in reverse order.
|
||||||
for i in (0..time_ranges_a.len()).rev() {
|
for i in (0..time_ranges_a.len()).rev() {
|
||||||
time_ranges_b
|
time_ranges_b
|
||||||
|
@ -58,7 +58,7 @@ fn add_order() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_overlapping() {
|
fn add_overlapping() {
|
||||||
let mut time_ranges = TimeRangesContainer::new();
|
let mut time_ranges = TimeRangesContainer::default();
|
||||||
|
|
||||||
time_ranges.add(0., 2.).unwrap();
|
time_ranges.add(0., 2.).unwrap();
|
||||||
time_ranges.add(10., 11.).unwrap();
|
time_ranges.add(10., 11.).unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue