summaryrefslogtreecommitdiffstats
path: root/libc
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2010-10-07 11:03:32 +0200
committerDavid 'Digit' Turner <digit@google.com>2010-10-07 11:03:32 +0200
commit5b81b918173b4bf446c1a85240c094e4dd77231f (patch)
treedd4cab2ff2183ab7a13833f343870d57baaa1250 /libc
parentaf00228b705b53165c132a22b30c2d6cbb9acd13 (diff)
downloadbionic-5b81b918173b4bf446c1a85240c094e4dd77231f.zip
bionic-5b81b918173b4bf446c1a85240c094e4dd77231f.tar.gz
bionic-5b81b918173b4bf446c1a85240c094e4dd77231f.tar.bz2
libc: optimize memmove() with memcpy() if possible.
Change-Id: I90e578fdc82e427caee8fa4157ce3f8c6c99926d
Diffstat (limited to 'libc')
-rw-r--r--libc/string/memmove.c5
1 files changed, 4 insertions, 1 deletions
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 @@ 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 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