diff options
author | Brian Cully <bjc@kublai.com> | 2019-08-13 10:37:09 -0400 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2019-08-13 10:37:09 -0400 |
commit | 9f270caa5d07dc93f38977ccb7b6b3089e06009d (patch) | |
tree | 2e3c289e72a5321bc9b64b18b389b382aee988e6 /src | |
parent | 5bd0da77407f51c7b8ccd11c6e852a166fda4df1 (diff) | |
download | starb-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.
Diffstat (limited to 'src')
-rwxr-xr-x | src/lib.rs | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -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(()) } |