Implement get_unchecked* functions for Vec2D
authorunc0rr
Tue, 16 Oct 2018 23:59:22 +0200
changeset 13935 5c9d963492bf
parent 13934 ff77c9920007
child 13936 9230aed8a32e
Implement get_unchecked* functions for Vec2D
rust/vec2d/src/lib.rs
--- a/rust/vec2d/src/lib.rs	Tue Oct 16 23:49:44 2018 +0300
+++ b/rust/vec2d/src/lib.rs	Tue Oct 16 23:59:22 2018 +0200
@@ -51,13 +51,23 @@
     }
 
     #[inline]
+    pub fn get(&self, row: usize, column: usize) -> Option<&<usize as SliceIndex<[T]>>::Output> {
+        self.data.get(row * self.width + column)
+    }
+
+    #[inline]
     pub fn get_mut(&mut self, row: usize, column: usize) -> Option<&mut <usize as SliceIndex<[T]>>::Output> {
         self.data.get_mut(row * self.width + column)
     }
 
     #[inline]
-    pub fn get(&self, row: usize, column: usize) -> Option<&<usize as SliceIndex<[T]>>::Output> {
-        self.data.get(row * self.width + column)
+    pub unsafe fn get_unchecked(&self, row: usize, column: usize) -> &<usize as SliceIndex<[T]>>::Output {
+        self.data.get_unchecked(row * self.width + column)
+    }
+
+    #[inline]
+    pub unsafe fn get_unchecked_mut(&mut self, row: usize, column: usize) -> &mut <usize as SliceIndex<[T]>>::Output {
+        self.data.get_unchecked_mut(row * self.width + column)
     }
 }