From 000a20e1b8bfd4730859dc7f3d7e1411e44bc32f Mon Sep 17 00:00:00 2001 From: DooMLoRD Date: Wed, 30 Apr 2014 20:16:48 +0530 Subject: lib/string: use glibc version the performance of memcpy and memmove of the general version is very inefficient, this patch improved them. Signed-off-by: Miao Xie Signed-off-by: faux123 Signed-off-by: Stefan Guendhoer --- lib/string.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/string.c b/lib/string.c index cb9ea2181..517f9f36f 100644 --- a/lib/string.c +++ b/lib/string.c @@ -26,6 +26,7 @@ #include #include #include +#include #ifndef __HAVE_ARCH_STRNICMP /** @@ -614,11 +615,11 @@ EXPORT_SYMBOL(memzero_explicit); */ void *memcpy(void *dest, const void *src, size_t count) { - char *tmp = dest; - const char *s = src; + unsigned long dstp = (unsigned long)dest; + unsigned long srcp = (unsigned long)src; - while (count--) - *tmp++ = *s++; + /* Copy from the beginning to the end */ + mem_copy_fwd(dstp, srcp, count); return dest; } EXPORT_SYMBOL(memcpy); @@ -635,21 +636,15 @@ EXPORT_SYMBOL(memcpy); */ void *memmove(void *dest, const void *src, size_t count) { - char *tmp; - const char *s; + unsigned long dstp = (unsigned long)dest; + unsigned long srcp = (unsigned long)src; - if (dest <= src) { - tmp = dest; - s = src; - while (count--) - *tmp++ = *s++; + if (dest - src >= count) { + /* Copy from the beginning to the end */ + mem_copy_fwd(dstp, srcp, count); } else { - tmp = dest; - tmp += count; - s = src; - s += count; - while (count--) - *--tmp = *--s; + /* Copy from the end to the beginning */ + mem_copy_bwd(dstp, srcp, count); } return dest; } -- cgit v1.2.3