am 5b81b918: libc: optimize memmove() with memcpy() if possible.
Merge commit '5b81b918173b4bf446c1a85240c094e4dd77231f' into gingerbread-plus-aosp
* commit '5b81b918173b4bf446c1a85240c094e4dd77231f':
libc: optimize memmove() with memcpy() if possible.
diff --git a/libc/string/memmove.c b/libc/string/memmove.c
index fcaf4ee..98ecfc9 100644
--- a/libc/string/memmove.c
+++ b/libc/string/memmove.c
@@ -31,7 +31,10 @@
{
const char *p = src;
char *q = dst;
- if (__builtin_expect(q < p, 1)) {
+ /* We can use the optimized memcpy if the destination is below the
+ * source (i.e. q < p), or if it is completely over it (i.e. q >= p+n).
+ */
+ if (__builtin_expect((q < p) || ((size_t)(q - p) >= n), 1)) {
return memcpy(dst, src, n);
} else {
#define PRELOAD_DISTANCE 64