diff options
Diffstat (limited to 'src/grid')
-rw-r--r-- | src/grid/row.rs | 19 | ||||
-rw-r--r-- | src/grid/storage.rs | 4 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/grid/row.rs b/src/grid/row.rs index 69a4f2b2..7c12bf99 100644 --- a/src/grid/row.rs +++ b/src/grid/row.rs @@ -15,7 +15,7 @@ //! Defines the Row type which makes up lines in the grid use std::ops::{Index, IndexMut}; -use std::ops::{Range, RangeTo, RangeFrom, RangeFull}; +use std::ops::{Range, RangeTo, RangeFrom, RangeFull, RangeToInclusive}; use std::cmp::{max, min}; use std::slice; @@ -200,3 +200,20 @@ impl<T> IndexMut<RangeFull> for Row<T> { &mut self.inner[..] } } + +impl<T> Index<RangeToInclusive<Column>> for Row<T> { + type Output = [T]; + + #[inline] + fn index(&self, index: RangeToInclusive<Column>) -> &[T] { + &self.inner[..=(index.end.0)] + } +} + +impl<T> IndexMut<RangeToInclusive<Column>> for Row<T> { + #[inline] + fn index_mut(&mut self, index: RangeToInclusive<Column>) -> &mut [T] { + self.occ = max(self.occ, *index.end); + &mut self.inner[..=(index.end.0)] + } +} diff --git a/src/grid/storage.rs b/src/grid/storage.rs index ad94cf2b..af2bd35c 100644 --- a/src/grid/storage.rs +++ b/src/grid/storage.rs @@ -232,8 +232,8 @@ impl<T> Storage<T> { // Cast to a qword array to opt out of copy restrictions and avoid // drop hazards. Byte array is no good here since for whatever // reason LLVM won't optimized it. - let a_ptr = self.inner.as_mut_ptr().offset(a as isize) as *mut u64; - let b_ptr = self.inner.as_mut_ptr().offset(b as isize) as *mut u64; + let a_ptr = self.inner.as_mut_ptr().add(a) as *mut u64; + let b_ptr = self.inner.as_mut_ptr().add(b) as *mut u64; // Copy 1 qword at a time // |