diff options
| author | DooMLoRD <metoo.mememe@gmail.com> | 2014-04-30 20:16:48 +0530 |
|---|---|---|
| committer | Moyster <oysterized@gmail.com> | 2016-08-26 20:06:35 +0200 |
| commit | 000a20e1b8bfd4730859dc7f3d7e1411e44bc32f (patch) | |
| tree | 54ece87cb5f2533c3e26c6e6bd428f1a38eac444 /lib | |
| parent | 7291759b62a75a4cab4140f653c572e117763060 (diff) | |
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 <miaox*******>
Signed-off-by: faux123 <reioux@gmail.com>
Signed-off-by: Stefan Guendhoer <stefan@guendhoer.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/string.c | 29 |
1 files changed, 12 insertions, 17 deletions
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 <linux/export.h> #include <linux/bug.h> #include <linux/errno.h> +#include <linux/memcopy.h> #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; } |
