simplify if/else handling on ringbuffer

This commit is contained in:
Alexandros Liarokapis 2024-10-02 13:10:07 +03:00
parent f0d2ebdc7e
commit 2ec05da5dd

View File

@ -111,10 +111,8 @@ impl<'a, W: Word> ReadableDmaRingBuffer<'a, W> {
let diff = self.write_index.diff(self.cap(), &self.read_index);
if diff < 0 {
return Err(Error::DmaUnsynced);
}
if diff > self.cap() as isize {
Err(Error::DmaUnsynced)
} else if diff > self.cap() as isize {
Err(Error::Overrun)
} else {
Ok(diff as usize)
@ -223,11 +221,10 @@ impl<'a, W: Word> WritableDmaRingBuffer<'a, W> {
let diff = self.write_index.diff(self.cap(), &self.read_index);
if diff > self.cap() as isize {
return Err(Error::DmaUnsynced);
}
if diff < 0 {
Err(Error::Overrun)
} else if diff > self.cap() as isize {
Err(Error::DmaUnsynced)
} else {
Ok(self.cap().saturating_sub(diff as usize))
}