From patchwork Tue Apr 12 06:58:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Weisser X-Patchwork-Id: 90725 X-Patchwork-Delegate: albert.aribaud@free.fr Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 6D8A7B6F1B for ; Tue, 12 Apr 2011 16:58:58 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 25E15281CB; Tue, 12 Apr 2011 08:58:57 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8kOC5ViwgIDc; Tue, 12 Apr 2011 08:58:57 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 41FAB281E1; Tue, 12 Apr 2011 08:58:55 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 13235281E9 for ; Tue, 12 Apr 2011 08:58:53 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GMy9lFWNTwlr for ; Tue, 12 Apr 2011 08:58:52 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-in-06.arcor-online.net (mail-in-06.arcor-online.net [151.189.21.46]) by theia.denx.de (Postfix) with ESMTPS id 057FC281E1 for ; Tue, 12 Apr 2011 08:58:50 +0200 (CEST) Received: from mail-in-09-z2.arcor-online.net (mail-in-09-z2.arcor-online.net [151.189.8.21]) by mx.arcor.de (Postfix) with ESMTP id 04B9310BC5D; Tue, 12 Apr 2011 08:58:50 +0200 (CEST) Received: from mail-in-01.arcor-online.net (mail-in-01.arcor-online.net [151.189.21.41]) by mail-in-09-z2.arcor-online.net (Postfix) with ESMTP id F1E4120422; Tue, 12 Apr 2011 08:58:49 +0200 (CEST) Received: from localhost.localdomain (unknown [212.87.136.142]) (Authenticated sender: weisserm@arcor.de) by mail-in-01.arcor-online.net (Postfix) with ESMTPA id 73EE715; Tue, 12 Apr 2011 08:58:49 +0200 (CEST) X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-01.arcor-online.net 73EE715 From: Matthias Weisser To: u-boot@lists.denx.de Date: Tue, 12 Apr 2011 08:58:40 +0200 Message-Id: <1302591520-12517-1-git-send-email-weisserm@arcor.de> X-Mailer: git-send-email 1.7.0.4 Subject: [U-Boot] [PATCH] Do not copy to same address X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de In some cases (e.g. bootm with a elf payload) there is a in place copy of data to the same address. Catching this saves some ms while booting. Signed-off-by: Matthias Weisser --- lib/string.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/lib/string.c b/lib/string.c index b375b81..b8a9203 100644 --- a/lib/string.c +++ b/lib/string.c @@ -445,6 +445,9 @@ char * bcopy(const char * src, char * dest, int count) { char *tmp = dest; + if (src == dest) + return dest; + while (count--) *tmp++ = *src++; @@ -467,6 +470,9 @@ void * memcpy(void *dest, const void *src, size_t count) unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src; char *d8, *s8; + if (src == dest) + return dest; + /* while all data is aligned (common case), copy a word at a time */ if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) { while (count >= sizeof(*dl)) { @@ -497,6 +503,9 @@ void * memmove(void * dest,const void *src,size_t count) { char *tmp, *s; + if (src == dest) + return dest; + if (dest <= src) { tmp = (char *) dest; s = (char *) src;