summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2010-09-28 00:15:05 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-09-28 00:15:05 -0700
commit79260746dbed91babab415ea86fba0e3eb086429 (patch)
treed2d601aa76389e72fd8aca11e950cbe32742ac6d
parent032a713549c12b79b5dde6ef3dff323b7698110d (diff)
parent80fba9a2fe4eacaabee99cf0bbead872c2792231 (diff)
downloadbionic-79260746dbed91babab415ea86fba0e3eb086429.zip
bionic-79260746dbed91babab415ea86fba0e3eb086429.tar.gz
bionic-79260746dbed91babab415ea86fba0e3eb086429.tar.bz2
Merge "libc: memmove(): non-overlapping block optim." into gingerbread
-rw-r--r--libc/string/memmove.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/libc/string/memmove.c b/libc/string/memmove.c
index fcaf4ee..948a766 100644
--- a/libc/string/memmove.c
+++ b/libc/string/memmove.c
@@ -31,7 +31,11 @@ void *memmove(void *dst, const void *src, size_t n)
{
const char *p = src;
char *q = dst;
- if (__builtin_expect(q < p, 1)) {
+
+ /* we can use highgly-optimized memcpy() if the destination
+ * is before the source, or if the two blocks are non-overlapping
+ */
+ if (__builtin_expect((q < p || (q-p) <= (ptrdiff_t)n), 1)) {
return memcpy(dst, src, n);
} else {
#define PRELOAD_DISTANCE 64