From c37fb2e45300a58e97fcc7d2f00ecf7db1f0fc72 Mon Sep 17 00:00:00 2001 From: tanishka <109246904+taniishkaaa@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:09:15 +0530 Subject: [PATCH] clippy: Fix `type_complexity` warning in `components/script/dom` (#33835) * clippy: Fix type_complexity warning in components/script/dom/bluetoothdevice.rs Signed-off-by: taniishkaaa * Fix clippy warnings due to code changes Signed-off-by: taniishkaaa * Move documentation comment Signed-off-by: taniishkaaa * Root the new struct Signed-off-by: taniishkaaa --------- Signed-off-by: taniishkaaa --- components/script/dom/bluetoothdevice.rs | 36 +++++++++++++----------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/components/script/dom/bluetoothdevice.rs b/components/script/dom/bluetoothdevice.rs index e9ea28ed6cb..a5da5f76ebc 100644 --- a/components/script/dom/bluetoothdevice.rs +++ b/components/script/dom/bluetoothdevice.rs @@ -33,6 +33,14 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; use crate::realms::InRealm; +#[crown::unrooted_must_root_lint::must_root] +#[derive(JSTraceable, MallocSizeOf)] +struct AttributeInstanceMap { + service_map: DomRefCell>>, + characteristic_map: DomRefCell>>, + descriptor_map: DomRefCell>>, +} + // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice #[dom_struct] pub struct BluetoothDevice { @@ -41,11 +49,7 @@ pub struct BluetoothDevice { name: Option, gatt: MutNullableDom, context: Dom, - attribute_instance_map: ( - DomRefCell>>, - DomRefCell>>, - DomRefCell>>, - ), + attribute_instance_map: AttributeInstanceMap, watching_advertisements: Cell, } @@ -61,11 +65,11 @@ impl BluetoothDevice { name, gatt: Default::default(), context: Dom::from_ref(context), - attribute_instance_map: ( - DomRefCell::new(HashMap::new()), - DomRefCell::new(HashMap::new()), - DomRefCell::new(HashMap::new()), - ), + attribute_instance_map: AttributeInstanceMap { + service_map: DomRefCell::new(HashMap::new()), + characteristic_map: DomRefCell::new(HashMap::new()), + descriptor_map: DomRefCell::new(HashMap::new()), + }, watching_advertisements: Cell::new(false), } } @@ -96,7 +100,7 @@ impl BluetoothDevice { service: &BluetoothServiceMsg, server: &BluetoothRemoteGATTServer, ) -> DomRoot { - let (ref service_map_ref, _, _) = self.attribute_instance_map; + let service_map_ref = &self.attribute_instance_map.service_map; let mut service_map = service_map_ref.borrow_mut(); if let Some(existing_service) = service_map.get(&service.instance_id) { return DomRoot::from_ref(existing_service); @@ -117,7 +121,7 @@ impl BluetoothDevice { characteristic: &BluetoothCharacteristicMsg, service: &BluetoothRemoteGATTService, ) -> DomRoot { - let (_, ref characteristic_map_ref, _) = self.attribute_instance_map; + let characteristic_map_ref = &self.attribute_instance_map.characteristic_map; let mut characteristic_map = characteristic_map_ref.borrow_mut(); if let Some(existing_characteristic) = characteristic_map.get(&characteristic.instance_id) { return DomRoot::from_ref(existing_characteristic); @@ -164,7 +168,7 @@ impl BluetoothDevice { descriptor: &BluetoothDescriptorMsg, characteristic: &BluetoothRemoteGATTCharacteristic, ) -> DomRoot { - let (_, _, ref descriptor_map_ref) = self.attribute_instance_map; + let descriptor_map_ref = &self.attribute_instance_map.descriptor_map; let mut descriptor_map = descriptor_map_ref.borrow_mut(); if let Some(existing_descriptor) = descriptor_map.get(&descriptor.instance_id) { return DomRoot::from_ref(existing_descriptor); @@ -198,13 +202,13 @@ impl BluetoothDevice { // https://github.com/WebBluetoothCG/web-bluetooth/issues/330 // Step 4. - let mut service_map = self.attribute_instance_map.0.borrow_mut(); + let mut service_map = self.attribute_instance_map.service_map.borrow_mut(); let service_ids = service_map.drain().map(|(id, _)| id).collect(); - let mut characteristic_map = self.attribute_instance_map.1.borrow_mut(); + let mut characteristic_map = self.attribute_instance_map.characteristic_map.borrow_mut(); let characteristic_ids = characteristic_map.drain().map(|(id, _)| id).collect(); - let mut descriptor_map = self.attribute_instance_map.2.borrow_mut(); + let mut descriptor_map = self.attribute_instance_map.descriptor_map.borrow_mut(); let descriptor_ids = descriptor_map.drain().map(|(id, _)| id).collect(); // Step 5, 6.4, 7.