From 9f270caa5d07dc93f38977ccb7b6b3089e06009d Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Tue, 13 Aug 2019 10:37:09 -0400 Subject: Use get_unchecked for backing array access. The index is guaranteed to be in bounds because it's always modulo the array capacity, so use the unchecked variants to get/set values. --- src/lib.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 23f2947..70e1386 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,8 +112,10 @@ where None } else { let nh = (h + 1) % CAPACITY; - let buf = unsafe { &mut *rb.buf.get() }; - let rc = Some(buf[h]); + let rc = unsafe { + let buf = &mut *rb.buf.get(); + Some(*buf.get_unchecked(h)) + }; rb.head.store(nh, Ordering::SeqCst); rc } @@ -144,8 +146,10 @@ where // `unshift`. In larger buffers it wastes a buffer slot. Err(Error::BufferFull) } else { - let buf = unsafe { &mut *rb.buf.get() }; - buf[t] = v; + unsafe { + let buf = &mut *rb.buf.get(); + *buf.get_unchecked_mut(t) = v; + } rb.tail.store(nt, Ordering::SeqCst); Ok(()) } -- cgit v1.2.3