From: Simon Glass Date: Fri, 20 Jan 2017 07:07:38 -0700 Subject: [U-Boot] [PATCH v4 03/17] string: Use memcpy() within memmove() when we can In-Reply-To: <20170120140752.16296-1-sjg@chromium.org> References: <20170120140752.16296-1-sjg@chromium.org> Message-ID: <20170120140752.16296-4-sjg@chromium.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de A common use of memmove() can be handled by memcpy(). Also memcpy() includes an optimisation for large sizes: it copies a word at a time. So we can get a speed-up by calling memcpy() to handle our move in this case. Update memmove() to call memcpy() if the destination is before the source. Signed-off-by: Simon Glass --- Changes in v4: None Changes in v3: None lib/string.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/string.c b/lib/string.c index 67d5f6a4213..6a75efb180b 100644 --- a/lib/string.c +++ b/lib/string.c @@ -509,16 +509,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; - while (count--) - *tmp++ = *s++; - } - else { + memcpy(dest, src, count); + } else { tmp = (char *) dest + count; s = (char *) src + count; while (count--) -- 2.11.0.483.g087da7b7c-goog