@@ -167,7 +167,7 @@ impl Table {
167167 #[ inline]
168168 pub fn ingredient_index ( & self , id : Id ) -> IngredientIndex {
169169 let ( page_idx, _) = split_id ( id) ;
170- self . pages [ page_idx. 0 ] . ingredient
170+ unsafe { self . pages . get_unchecked ( page_idx. 0 ) . ingredient }
171171 }
172172
173173 /// Get a reference to the data for `id`, which must have been allocated from this table with type `T`.
@@ -178,7 +178,7 @@ impl Table {
178178 pub ( crate ) fn get < T : Slot > ( & self , id : Id ) -> & T {
179179 let ( page, slot) = split_id ( id) ;
180180 let page_ref = self . page :: < T > ( page) ;
181- & page_ref. data ( ) [ slot. 0 ]
181+ unsafe { page_ref. data ( ) . get_unchecked ( slot. 0 ) }
182182 }
183183
184184 /// Get a raw pointer to the data for `id`, which must have been allocated from this table.
@@ -193,7 +193,7 @@ impl Table {
193193 pub ( crate ) fn get_raw < T : Slot > ( & self , id : Id ) -> * mut T {
194194 let ( page, slot) = split_id ( id) ;
195195 let page_ref = self . page :: < T > ( page) ;
196- page_ref. page_data ( ) [ slot. 0 ] . get ( ) . cast :: < T > ( )
196+ unsafe { page_ref. page_data ( ) . get_unchecked ( slot. 0 ) . get ( ) . cast :: < T > ( ) }
197197 }
198198
199199 /// Gets a reference to the page which has slots of type `T`
@@ -203,7 +203,7 @@ impl Table {
203203 /// If `page` is out of bounds or the type `T` is incorrect.
204204 #[ inline]
205205 pub ( crate ) fn page < T : Slot > ( & self , page : PageIndex ) -> PageView < ' _ , T > {
206- self . pages [ page. 0 ] . assert_type :: < T > ( )
206+ unsafe { self . pages . get_unchecked ( page. 0 ) . assert_type :: < T > ( ) }
207207 }
208208
209209 /// Allocate a new page for the given ingredient and with slots of type `T`
@@ -228,7 +228,7 @@ impl Table {
228228 current_revision : Revision ,
229229 ) -> MemoTableWithTypes < ' _ > {
230230 let ( page, slot) = split_id ( id) ;
231- let page = & self . pages [ page. 0 ] ;
231+ let page = unsafe { self . pages . get_unchecked ( page. 0 ) } ;
232232 // SAFETY: We supply a proper slot pointer and the caller is required to pass the `current_revision`.
233233 let memos = unsafe { & * ( page. slot_vtable . memos ) ( page. get ( slot) , current_revision) } ;
234234 // SAFETY: The `Page` keeps the correct memo types.
@@ -239,10 +239,7 @@ impl Table {
239239 pub ( crate ) fn memos_mut ( & mut self , id : Id ) -> MemoTableWithTypesMut < ' _ > {
240240 let ( page, slot) = split_id ( id) ;
241241 let page_index = page. 0 ;
242- let page = self
243- . pages
244- . get_mut ( page_index)
245- . unwrap_or_else ( || panic ! ( "index `{page_index}` is uninitialized" ) ) ;
242+ let page = unsafe { self . pages . get_unchecked_mut ( page_index) } ;
246243 // SAFETY: We supply a proper slot pointer and the caller is required to pass the `current_revision`.
247244 let memos = unsafe { & mut * ( page. slot_vtable . memos_mut ) ( page. get ( slot) ) } ;
248245 // SAFETY: The `Page` keeps the correct memo types.
0 commit comments