Skip to content

Commit

Permalink
use usize instead of isize for buffer offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Feb 9, 2024
1 parent f63ffdb commit 027e762
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<'a> BufferDir<'a> {
pub unsafe fn from_raw_parts(
dir: BusDir,
ptrs: &'a [*mut f32],
offset: isize,
offset: usize,
len: usize,
) -> BufferDir<'a> {
match dir {
Expand All @@ -42,7 +42,7 @@ pub struct BusData {
pub struct Buffers<'a> {
buses: &'a [BusData],
ptrs: &'a [*mut f32],
offset: isize,
offset: usize,
len: usize,
_marker: PhantomData<&'a mut f32>,
}
Expand All @@ -52,7 +52,7 @@ impl<'a> Buffers<'a> {
pub unsafe fn from_raw_parts(
buses: &'a [BusData],
ptrs: &'a [*mut f32],
offset: isize,
offset: usize,
len: usize,
) -> Buffers<'a> {
Buffers {
Expand Down Expand Up @@ -122,7 +122,7 @@ impl<'a> Buffers<'a> {
Some(Buffers {
buses: self.buses,
ptrs: self.ptrs,
offset: self.offset.checked_add_unsigned(range.start).unwrap(),
offset: self.offset + range.start,
len: range.end - range.start,
_marker: self._marker,
})
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<'a> IntoIterator for Buffers<'a> {
pub struct Buses<'a> {
iter: slice::Iter<'a, BusData>,
ptrs: &'a [*mut f32],
offset: isize,
offset: usize,
len: usize,
_marker: PhantomData<&'a mut f32>,
}
Expand All @@ -181,14 +181,14 @@ impl<'a> Iterator for Buses<'a> {

pub struct Buffer<'a> {
ptrs: &'a [*mut f32],
offset: isize,
offset: usize,
len: usize,
_marker: PhantomData<&'a f32>,
}

impl<'a> Buffer<'a> {
#[inline]
pub unsafe fn from_raw_parts(ptrs: &'a [*mut f32], offset: isize, len: usize) -> Buffer<'a> {
pub unsafe fn from_raw_parts(ptrs: &'a [*mut f32], offset: usize, len: usize) -> Buffer<'a> {
Buffer {
ptrs,
offset,
Expand All @@ -213,20 +213,20 @@ impl<'a> Index<usize> for Buffer<'a> {

#[inline]
fn index(&self, index: usize) -> &[f32] {
unsafe { slice::from_raw_parts(self.ptrs[index].offset(self.offset), self.len) }
unsafe { slice::from_raw_parts(self.ptrs[index].add(self.offset), self.len) }
}
}

pub struct BufferMut<'a> {
ptrs: &'a [*mut f32],
offset: isize,
offset: usize,
len: usize,
_marker: PhantomData<&'a mut f32>,
}

impl<'a> BufferMut<'a> {
#[inline]
pub unsafe fn from_raw_parts(ptrs: &'a [*mut f32], offset: isize, len: usize) -> BufferMut<'a> {
pub unsafe fn from_raw_parts(ptrs: &'a [*mut f32], offset: usize, len: usize) -> BufferMut<'a> {
BufferMut {
ptrs,
offset,
Expand All @@ -251,13 +251,13 @@ impl<'a> Index<usize> for BufferMut<'a> {

#[inline]
fn index(&self, index: usize) -> &[f32] {
unsafe { slice::from_raw_parts(self.ptrs[index].offset(self.offset), self.len) }
unsafe { slice::from_raw_parts(self.ptrs[index].add(self.offset), self.len) }
}
}

impl<'a> IndexMut<usize> for BufferMut<'a> {
#[inline]
fn index_mut(&mut self, index: usize) -> &mut [f32] {
unsafe { slice::from_raw_parts_mut(self.ptrs[index].offset(self.offset), self.len) }
unsafe { slice::from_raw_parts_mut(self.ptrs[index].add(self.offset), self.len) }
}
}
2 changes: 1 addition & 1 deletion src/buffers/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'a, 'b> Iterator for SplitAtEvents<'a, 'b> {
len: split,
_marker: PhantomData,
};
self.buffers.offset += split as isize;
self.buffers.offset += split;
self.buffers.len -= split;

let events = self.events.slice(..event_count).unwrap();
Expand Down

0 comments on commit 027e762

Please sign in to comment.