diff --git a/ports/geckolib/gecko_bindings/sugar/ns_t_array.rs b/ports/geckolib/gecko_bindings/sugar/ns_t_array.rs index 6ea27d01a8d..57b6495b040 100644 --- a/ports/geckolib/gecko_bindings/sugar/ns_t_array.rs +++ b/ports/geckolib/gecko_bindings/sugar/ns_t_array.rs @@ -3,20 +3,27 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::mem; -use std::ops::{Index, IndexMut}; +use std::ops::{Deref, DerefMut}; +use std::slice; use structs::{nsTArray, nsTArrayHeader}; -impl Index for nsTArray { - type Output = T; +impl Deref for nsTArray { + type Target = [T]; - fn index<'a>(&'a self, index: u32) -> &'a T { - unsafe { mem::transmute(self.ptr_at(index)) } + fn deref<'a>(&'a self) -> &'a [T] { + unsafe { + slice::from_raw_parts(self.slice_begin(), + self.header().mLength as usize) + } } } -impl IndexMut for nsTArray { - fn index_mut<'a>(&'a mut self, index: u32) -> &'a mut T { - unsafe { mem::transmute(self.ptr_at_mut(index)) } +impl DerefMut for nsTArray { + fn deref_mut<'a>(&'a mut self) -> &'a mut [T] { + unsafe { + slice::from_raw_parts_mut(self.slice_begin(), + self.header().mLength as usize) + } } } @@ -27,30 +34,9 @@ impl nsTArray { unsafe { mem::transmute(self.mBuffer) } } - #[inline] - pub fn len(&self) -> u32 { - self.header().mLength - } - #[inline] unsafe fn slice_begin(&self) -> *mut T { debug_assert!(!self.mBuffer.is_null()); (self.mBuffer as *const nsTArrayHeader).offset(1) as *mut _ } - - #[inline] - fn ptr_at_mut(&mut self, index: u32) -> *mut T { - debug_assert!(index <= self.len()); - unsafe { - self.slice_begin().offset(index as isize) - } - } - - #[inline] - fn ptr_at(&self, index: u32) -> *const T { - debug_assert!(index <= self.len()); - unsafe { - self.slice_begin().offset(index as isize) - } - } } diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 4e0d8f3879b..e944a6e1725 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -805,7 +805,7 @@ fn static_assert() { }; let mut stop = unsafe { - &mut (*gecko_gradient).mStops[index as u32] + &mut (*gecko_gradient).mStops[index] }; stop.mColor = color;