Commit b038db852b5b7120f1ff825d8e2a5c2cd14c2f0f
Committed by
Wolfgang Denk
1 parent
942e31437d
Exists in
master
and in
54 other branches
memcpy/memmove: Do not copy to same address
In some cases (e.g. bootm with a elf payload which is already at the right position) there is a in place copy of data to the same address. Catching this saves some ms while booting. Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Showing 1 changed file with 6 additions and 0 deletions Side-by-side Diff
lib/string.c
... | ... | @@ -467,6 +467,9 @@ |
467 | 467 | unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src; |
468 | 468 | char *d8, *s8; |
469 | 469 | |
470 | + if (src == dest) | |
471 | + return dest; | |
472 | + | |
470 | 473 | /* while all data is aligned (common case), copy a word at a time */ |
471 | 474 | if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) { |
472 | 475 | while (count >= sizeof(*dl)) { |
... | ... | @@ -496,6 +499,9 @@ |
496 | 499 | void * memmove(void * dest,const void *src,size_t count) |
497 | 500 | { |
498 | 501 | char *tmp, *s; |
502 | + | |
503 | + if (src == dest) | |
504 | + return dest; | |
499 | 505 | |
500 | 506 | if (dest <= src) { |
501 | 507 | tmp = (char *) dest; |