From afc8e38fc13ae462bd65914eebb468526c4e6a0b Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Sat, 22 Jun 2024 23:58:20 -0700 Subject: [PATCH] [naga] Use `HandleVec` in `Layouter`. Change `naga::proc::layouter::Layouter::layouts` to be a `HandleVec`, not a `Vec`. --- naga/src/proc/layouter.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/naga/src/proc/layouter.rs b/naga/src/proc/layouter.rs index 1c78a594d1..82b1be094a 100644 --- a/naga/src/proc/layouter.rs +++ b/naga/src/proc/layouter.rs @@ -1,4 +1,4 @@ -use crate::arena::Handle; +use crate::arena::{Handle, HandleVec}; use std::{fmt::Display, num::NonZeroU32, ops}; /// A newtype struct where its only valid values are powers of 2 @@ -108,17 +108,15 @@ impl TypeLayout { /// /// [WGSL ยง4.3.7, "Memory Layout"](https://gpuweb.github.io/gpuweb/wgsl/#memory-layouts) #[derive(Debug, Default)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize))] -#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct Layouter { - /// Layouts for types in an arena, indexed by `Handle` index. - layouts: Vec, + /// Layouts for types in an arena. + layouts: HandleVec, } impl ops::Index> for Layouter { type Output = TypeLayout; fn index(&self, handle: Handle) -> &TypeLayout { - &self.layouts[handle.index()] + &self.layouts[handle] } } @@ -243,7 +241,7 @@ impl Layouter { }, }; debug_assert!(size <= layout.size); - self.layouts.push(layout); + self.layouts.insert(ty_handle, layout); } Ok(())