]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
memcpy/memmove: Do not copy to same address
authorMatthias Weisser <weisserm@arcor.de>
Sun, 22 May 2011 23:03:55 +0000 (23:03 +0000)
committerWolfgang Denk <wd@denx.de>
Mon, 25 Jul 2011 22:28:44 +0000 (00:28 +0200)
In some cases (e.g. bootm with a elf payload which is already at the right
position) there is a in place copy of data to the same address. Catching this
saves some ms while booting.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
lib/string.c

index b375b8124a9a1879a831d79b8f956bf8ae8a9537..2c4f0ec9a11f8e7219b9c5d40659616bf4bc6aaf 100644 (file)
@@ -467,6 +467,9 @@ void * memcpy(void *dest, const void *src, size_t count)
        unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
        char *d8, *s8;
 
+       if (src == dest)
+               return dest;
+
        /* while all data is aligned (common case), copy a word at a time */
        if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) {
                while (count >= sizeof(*dl)) {
@@ -497,6 +500,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;