Skip to content

Commit c8ebbfb

Browse files
committed
Replace ad-hoc copy_memory function with [T]::copy_from_slice
1 parent 8394297 commit c8ebbfb

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

src/atom.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::hash::{Hash, Hasher};
2323
use std::marker::PhantomData;
2424
use std::mem;
2525
use std::ops;
26-
use std::ptr;
2726
use std::slice;
2827
use std::str;
2928
use std::sync::Mutex;
@@ -314,7 +313,7 @@ impl<'a, Static: StaticAtomSet> From<Cow<'a, str>> for Atom<Static> {
314313
let len = string_to_add.len();
315314
if len <= MAX_INLINE_LEN {
316315
let mut buf: [u8; 7] = [0; 7];
317-
copy_memory(string_to_add.as_bytes(), &mut buf);
316+
buf[..len].copy_from_slice(string_to_add.as_bytes());
318317
Inline(len as u8, buf)
319318
} else {
320319
Dynamic(STRING_CACHE.lock().unwrap().add(string_to_add, hash) as *mut ())
@@ -571,7 +570,7 @@ impl UnpackedAtom {
571570
let mut data: u64 = (INLINE_TAG as u64) | ((len as u64) << 4);
572571
{
573572
let dest = inline_atom_slice_mut(&mut data);
574-
copy_memory(&buf[..], dest);
573+
dest.copy_from_slice(&buf)
575574
}
576575
data
577576
}
@@ -590,7 +589,7 @@ impl UnpackedAtom {
590589
debug_assert!(len <= MAX_INLINE_LEN);
591590
let mut buf: [u8; 7] = [0; 7];
592591
let src = inline_atom_slice(&data);
593-
copy_memory(src, &mut buf[..]);
592+
buf.copy_from_slice(src);
594593
Inline(len as u8, buf)
595594
},
596595
_ => debug_unreachable!(),
@@ -623,21 +622,6 @@ unsafe fn inline_orig_bytes<'a>(data: &'a u64) -> &'a [u8] {
623622
}
624623
}
625624

626-
627-
/// Copy of std::slice::bytes::copy_memory, which is unstable.
628-
#[inline]
629-
fn copy_memory(src: &[u8], dst: &mut [u8]) {
630-
let len_src = src.len();
631-
assert!(dst.len() >= len_src);
632-
// `dst` is unaliasable, so we know statically it doesn't overlap
633-
// with `src`.
634-
unsafe {
635-
ptr::copy_nonoverlapping(src.as_ptr(),
636-
dst.as_mut_ptr(),
637-
len_src);
638-
}
639-
}
640-
641625
#[cfg(test)]
642626
#[macro_use]
643627
mod tests {

0 commit comments

Comments
 (0)