aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass2017-04-05 16:23:31 -0600
committerTom Rini2017-05-09 20:19:04 -0400
commitcb0eae8cf8aaca76910dee4c7eb536d0814d1bd2 (patch)
tree8e4bb6377bcafcd626ed0bcbcdf960fad5cd1ceb
parent20b429b013c97cb3d253274003d52bbe8c9c4da1 (diff)
string: Use memcpy() within memmove() when we can
A common use of memmove() can be handled by memcpy(). Also memcpy() includes an optimisation for large sizes: it copies a word at a time. So we can get a speed-up by calling memcpy() to handle our move in this case. Update memmove() to call memcpy() if the destination is before the source. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
-rw-r--r--lib/string.c11
1 files changed, 2 insertions, 9 deletions
diff --git a/lib/string.c b/lib/string.c
index c1a28c14ced..e94021c4680 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -511,16 +511,9 @@ void * memmove(void * dest,const void *src,size_t count)
{
char *tmp, *s;
- if (src == dest)
- return dest;
-
if (dest <= src) {
- tmp = (char *) dest;
- s = (char *) src;
- while (count--)
- *tmp++ = *s++;
- }
- else {
+ memcpy(dest, src, count);
+ } else {
tmp = (char *) dest + count;
s = (char *) src + count;
while (count--)