Avoid calling custom memcpy implementation on some platforms

Custom memcpy implementation performs well on the platforms on which
unaligned read/write operation is fast. Otherwise we should use libc
implementation.
This commit is contained in:
Kogia-sima 2021-01-25 19:54:58 +09:00
parent 5209876df4
commit 67f49bdd18
2 changed files with 17 additions and 1 deletions

View File

@ -89,6 +89,7 @@ pub(super) unsafe fn escape_small(feed: &str, mut buf: *mut u8) -> usize {
buf as usize - buf_begin as usize
}
#[cfg(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"))]
#[inline]
pub(super) unsafe fn push_escaped_str(value: &str, buffer: &mut Buffer) {
buffer.reserve_small(value.len());
@ -105,3 +106,9 @@ pub(super) unsafe fn push_escaped_str(value: &str, buffer: &mut Buffer) {
buffer._set_len(buffer.len() + value.len());
}
#[cfg(not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64")))]
#[inline]
pub(super) unsafe fn push_escaped_str(value: &str, buffer: &mut Buffer) {
buffer.push_str(value);
}

View File

@ -38,8 +38,10 @@ macro_rules! unlikely {
};
}
/// memcpy implementation based on glibc (https://github.molgen.mpg.de/git-mirror/glibc/blob/master/sysdeps/x86_64/multiarch/memcpy-avx-unaligned.S)
/// Custom memcpy implementation is faster on some platforms
/// implementation based on glibc (https://github.molgen.mpg.de/git-mirror/glibc/blob/master/sysdeps/x86_64/multiarch/memcpy-avx-unaligned.S)
#[allow(clippy::cast_ptr_alignment)]
#[cfg(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"))]
pub unsafe fn memcpy_16(src: *const u8, dst: *mut u8, len: usize) {
debug_assert!(len <= 16);
let len_u8 = len as u8;
@ -66,3 +68,10 @@ pub unsafe fn memcpy_16(src: *const u8, dst: *mut u8, len: usize) {
*dst = *src;
}
}
#[cfg(not(any(
target_arch = "x86_64",
target_arch = "x86",
target_arch = "aarch64"
)))]
pub use ptr::copy_nonoverlapping as memcpy_16;