summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2010-09-26 22:40:02 +0200
committerDavid 'Digit' Turner <digit@google.com>2010-09-27 17:34:41 +0200
commit80fba9a2fe4eacaabee99cf0bbead872c2792231 (patch)
tree35cf24d62149365bdad0994d837654e3d05399d9
parentb9e49ad56e5776ace7c6eab2e997d5b7acb16792 (diff)
downloadbionic-80fba9a2fe4eacaabee99cf0bbead872c2792231.zip
bionic-80fba9a2fe4eacaabee99cf0bbead872c2792231.tar.gz
bionic-80fba9a2fe4eacaabee99cf0bbead872c2792231.tar.bz2
libc: memmove(): non-overlapping block optim.
Change-Id: I5652f4f97ca59d95176443fc27c737ef76258183
-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