diff options
author | Istvan Miklos <istvan.miklos@h-lab.eu> | 2020-01-30 12:39:39 +0100 |
---|---|---|
committer | Istvan Miklos <istvan.miklos@h-lab.eu> | 2020-01-30 12:39:39 +0100 |
commit | 0842e53d8de7b8dc50c5cf0b8c16144c99ce51a8 (patch) | |
tree | 20e305dc979c104608153647d9976501de2dd576 /components/script/dom/identityhub.rs | |
parent | 8e0d037ee82da747fa9c13234d5c3677f930e690 (diff) | |
download | servo-0842e53d8de7b8dc50c5cf0b8c16144c99ce51a8.tar.gz servo-0842e53d8de7b8dc50c5cf0b8c16144c99ce51a8.zip |
Remove code duplication from IdentityHub
Outsourced the backend selection to a function.
Diffstat (limited to 'components/script/dom/identityhub.rs')
-rw-r--r-- | components/script/dom/identityhub.rs | 62 |
1 files changed, 18 insertions, 44 deletions
diff --git a/components/script/dom/identityhub.rs b/components/script/dom/identityhub.rs index 91ead1acf0a..d0999d1848d 100644 --- a/components/script/dom/identityhub.rs +++ b/components/script/dom/identityhub.rs @@ -82,6 +82,20 @@ impl Identities { } } + fn select(&mut self, backend: Backend) -> &mut IdentityHub { + match backend { + #[cfg(any(target_os = "linux", target_os = "windows"))] + Backend::Vulkan => &mut self.vk_hub, + #[cfg(target_os = "windows")] + Backend::Dx12 => &mut self.dx12_hub, + #[cfg(target_os = "windows")] + Backend::Dx11 => &mut self.dx11_hub, + #[cfg(any(target_os = "ios", target_os = "macos"))] + Backend::Metal => &mut self.metal_hub, + _ => &mut self.dummy_hub, + } + } + fn hubs(&mut self) -> Vec<&mut IdentityHub> { vec![ #[cfg(any(target_os = "linux", target_os = "windows"))] @@ -97,17 +111,7 @@ impl Identities { } pub fn create_device_id(&mut self, backend: Backend) -> DeviceId { - match backend { - #[cfg(any(target_os = "linux", target_os = "windows"))] - Backend::Vulkan => self.vk_hub.create_device_id(), - #[cfg(target_os = "windows")] - Backend::Dx12 => self.dx12_hub.create_device_id(), - #[cfg(target_os = "windows")] - Backend::Dx11 => self.dx11_hub.create_device_id(), - #[cfg(any(target_os = "ios", target_os = "macos"))] - Backend::Metal => self.metal_hub.create_device_id(), - _ => self.dummy_hub.create_device_id(), - } + self.select(backend).create_device_id() } pub fn create_adapter_ids(&mut self) -> SmallVec<[AdapterId; 4]> { @@ -119,44 +123,14 @@ impl Identities { } pub fn create_buffer_id(&mut self, backend: Backend) -> BufferId { - match backend { - #[cfg(any(target_os = "linux", target_os = "windows"))] - Backend::Vulkan => self.vk_hub.create_buffer_id(), - #[cfg(target_os = "windows")] - Backend::Dx12 => self.dx12_hub.create_buffer_id(), - #[cfg(target_os = "windows")] - Backend::Dx11 => self.dx11_hub.create_buffer_id(), - #[cfg(any(target_os = "ios", target_os = "macos"))] - Backend::Metal => self.metal_hub.create_buffer_id(), - _ => self.dummy_hub.create_buffer_id(), - } + self.select(backend).create_buffer_id() } pub fn create_bind_group_layout_id(&mut self, backend: Backend) -> BindGroupLayoutId { - match backend { - #[cfg(any(target_os = "linux", target_os = "windows"))] - Backend::Vulkan => self.vk_hub.create_bind_group_layout_id(), - #[cfg(target_os = "windows")] - Backend::Dx12 => self.dx12_hub.create_bind_group_layout_id(), - #[cfg(target_os = "windows")] - Backend::Dx11 => self.dx11_hub.create_bind_group_layout_id(), - #[cfg(any(target_os = "ios", target_os = "macos"))] - Backend::Metal => self.metal_hub.create_bind_group_layout_id(), - _ => self.dummy_hub.create_bind_group_layout_id(), - } + self.select(backend).create_bind_group_layout_id() } pub fn create_pipeline_layout_id(&mut self, backend: Backend) -> PipelineLayoutId { - match backend { - #[cfg(any(target_os = "linux", target_os = "windows"))] - Backend::Vulkan => self.vk_hub.create_pipeline_layout_id(), - #[cfg(target_os = "windows")] - Backend::Dx12 => self.dx12_hub.create_pipeline_layout_id(), - #[cfg(target_os = "windows")] - Backend::Dx11 => self.dx11_hub.create_pipeline_layout_id(), - #[cfg(any(target_os = "ios", target_os = "macos"))] - Backend::Metal => self.metal_hub.create_pipeline_layout_id(), - _ => self.dummy_hub.create_pipeline_layout_id(), - } + self.select(backend).create_pipeline_layout_id() } } |