aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2019-08-13 10:37:09 -0400
committerBrian Cully <bjc@kublai.com>2019-08-13 10:37:09 -0400
commit9f270caa5d07dc93f38977ccb7b6b3089e06009d (patch)
tree2e3c289e72a5321bc9b64b18b389b382aee988e6
parent5bd0da77407f51c7b8ccd11c6e852a166fda4df1 (diff)
downloadstarb-9f270caa5d07dc93f38977ccb7b6b3089e06009d.tar.gz
starb-9f270caa5d07dc93f38977ccb7b6b3089e06009d.zip
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.
-rwxr-xr-xsrc/lib.rs12
1 files changed, 8 insertions, 4 deletions
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(())
}