Skip to content

Commit

Permalink
Use FlexZeroSlice constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Jun 10, 2022
1 parent 36fdb8d commit daec8eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions utils/zerovec/src/flexzerovec/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use core::cmp::Ordering;
use core::fmt;
use core::mem;
use core::ops::Range;
use crate::ule::{ULE, RawBytesULE};


const USIZE_WIDTH: usize = mem::size_of::<usize>();

Expand Down Expand Up @@ -164,6 +166,11 @@ impl FlexZeroSlice {
FlexZeroVec::Borrowed(self)
}

#[inline]
pub(crate) unsafe fn as_ule_slice_unchecked<const N: usize>(&self) -> &[RawBytesULE<N>] where RawBytesULE<N>: ULE {
RawBytesULE::<N>::from_byte_slice_unchecked(&self.data)
}

/// Returns the number of elements in the `FlexZeroSlice`.
#[inline]
pub fn len(&self) -> usize {
Expand Down
3 changes: 2 additions & 1 deletion utils/zerovec/src/varzerovec/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::flexzerovec::FlexZeroSlice;
use crate::ule::*;
use alloc::boxed::Box;
use alloc::format;
Expand Down Expand Up @@ -289,7 +290,7 @@ impl<'a, T: VarULE + ?Sized> VarZeroVecComponents<'a, T> {

#[inline]
fn indices_slice(&self) -> &'a [RawBytesULE<INDEX_WIDTH>] {
unsafe { RawBytesULE::<INDEX_WIDTH>::from_byte_slice_unchecked(self.indices.get_unchecked(1..)) }
unsafe { FlexZeroSlice::from_byte_slice_unchecked(self.indices).as_ule_slice_unchecked() }
}

// Dump a debuggable representation of this type
Expand Down

0 comments on commit daec8eb

Please sign in to comment.