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 <tanishkasingh2004@gmail.com>

* Fix clippy warnings due to code changes

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

* Move documentation comment

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

* Root the new struct

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>

---------

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
This commit is contained in:
tanishka 2024-10-15 13:09:15 +05:30 committed by GitHub
parent b088a8b8f1
commit c37fb2e453
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<HashMap<String, Dom<BluetoothRemoteGATTService>>>,
characteristic_map: DomRefCell<HashMap<String, Dom<BluetoothRemoteGATTCharacteristic>>>,
descriptor_map: DomRefCell<HashMap<String, Dom<BluetoothRemoteGATTDescriptor>>>,
}
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice
#[dom_struct]
pub struct BluetoothDevice {
@ -41,11 +49,7 @@ pub struct BluetoothDevice {
name: Option<DOMString>,
gatt: MutNullableDom<BluetoothRemoteGATTServer>,
context: Dom<Bluetooth>,
attribute_instance_map: (
DomRefCell<HashMap<String, Dom<BluetoothRemoteGATTService>>>,
DomRefCell<HashMap<String, Dom<BluetoothRemoteGATTCharacteristic>>>,
DomRefCell<HashMap<String, Dom<BluetoothRemoteGATTDescriptor>>>,
),
attribute_instance_map: AttributeInstanceMap,
watching_advertisements: Cell<bool>,
}
@ -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<BluetoothRemoteGATTService> {
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<BluetoothRemoteGATTCharacteristic> {
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<BluetoothRemoteGATTDescriptor> {
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.