Merge "memmove: Don't call memcpy if regions overlap"
This commit is contained in:
commit
86a4fca0b4
@ -32,10 +32,11 @@ void *memmove(void *dst, const void *src, size_t n)
|
|||||||
{
|
{
|
||||||
const char *p = src;
|
const char *p = src;
|
||||||
char *q = dst;
|
char *q = dst;
|
||||||
/* We can use the optimized memcpy if the destination is below the
|
/* We can use the optimized memcpy if the source and destination
|
||||||
* source (i.e. q < p), or if it is completely over it (i.e. q >= p+n).
|
* don't overlap.
|
||||||
*/
|
*/
|
||||||
if (__builtin_expect((q < p) || ((size_t)(q - p) >= n), 1)) {
|
if (__builtin_expect(((q < p) && ((size_t)(p - q) >= n))
|
||||||
|
|| ((p < q) && ((size_t)(q - p) >= n)), 1)) {
|
||||||
return memcpy(dst, src, n);
|
return memcpy(dst, src, n);
|
||||||
} else {
|
} else {
|
||||||
bcopy(src, dst, n);
|
bcopy(src, dst, n);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user