remove dependency of memmove on memcpy direction
authorRich Felker <dalias@aerifal.cx>
Fri, 7 Sep 2012 00:25:48 +0000 (20:25 -0400)
committerRich Felker <dalias@aerifal.cx>
Fri, 7 Sep 2012 00:25:48 +0000 (20:25 -0400)
this commit introduces a performance regression in many uses of
memmove, which will need to be addressed before the next release. i'm
making it as a temporary measure so that the restrict patch can be
committed without invoking undefined behavior when memmove calls
memcpy with overlapping regions.

src/string/memmove.c

index 22bb4b3..9153a64 100644 (file)
@@ -5,10 +5,9 @@ void *memmove(void *dest, const void *src, size_t n)
        char *d = dest;
        const char *s = src;
        if (d==s) return d;
        char *d = dest;
        const char *s = src;
        if (d==s) return d;
-       if ((size_t)(d-s) < n) {
+       if ((size_t)(d-s) < n)
                while (n--) d[n] = s[n];
                while (n--) d[n] = s[n];
-               return dest;
-       }
-       /* Assumes memcpy is overlap-safe when dest < src */
-       return memcpy(d, s, n);
+       else
+               while (n--) *d++ = *s++;
+       return dest;
 }
 }