瀏覽代碼

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>
Matthias Weisser 14 年之前
父節點
當前提交
b038db852b
共有 1 個文件被更改,包括 6 次插入0 次删除
  1. 6 0
      lib/string.c

+ 6 - 0
lib/string.c

@@ -467,6 +467,9 @@ void * memcpy(void *dest, const void *src, size_t count)
 	unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
 	unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
 	char *d8, *s8;
 	char *d8, *s8;
 
 
+	if (src == dest)
+		return dest;
+
 	/* while all data is aligned (common case), copy a word at a time */
 	/* while all data is aligned (common case), copy a word at a time */
 	if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) {
 	if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) {
 		while (count >= sizeof(*dl)) {
 		while (count >= sizeof(*dl)) {
@@ -497,6 +500,9 @@ void * memmove(void * dest,const void *src,size_t count)
 {
 {
 	char *tmp, *s;
 	char *tmp, *s;
 
 
+	if (src == dest)
+		return dest;
+
 	if (dest <= src) {
 	if (dest <= src) {
 		tmp = (char *) dest;
 		tmp = (char *) dest;
 		s = (char *) src;
 		s = (char *) src;