From patchwork Wed Feb 6 14:58:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 31328 Received: (qmail 109819 invoked by alias); 6 Feb 2019 14:59:04 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 109745 invoked by uid 89); 6 Feb 2019 14:59:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qk1-f195.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=20SJ21tlZpNhS1XJTfqXZ9f9nW5s8hKP6KYDk0x+OEA=; b=CWqzzSOC6tKXEOnIueTGBMbZ69CBu7odn4vgEGqVzhBa8POlifoRggqIBid159dIln 59qJLOcnWcfHFlWlEjHCu5clGDCpiEPZqbOxGmmJys05c8ZoKpmua6PiymrHW3L028RT 7c2I4xZX1pdGUL0HHQvZeMGge2LHCRFfpW0yfgXmdd8kZPsBDS8B3lwsX0dnlzRsoTwf PYwV0UOIhZEF+q7qLFmVQ0j069tVj4JUGeUGaaT7y9W6nbR9pJpaPLYxJ9rN+hr8ddmn v3cV9wIIRphhWDPLEWcNbxOxmFCMPScKBH8++qHiuWntTVHfpXN5pVRo4LcJfIzfRRmL DqSg== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 5/7] wcsmbs: optimize wcsncat Date: Wed, 6 Feb 2019 12:58:48 -0200 Message-Id: <20190206145850.22003-5-adhemerval.zanella@linaro.org> In-Reply-To: <20190206145850.22003-1-adhemerval.zanella@linaro.org> References: <20190206145850.22003-1-adhemerval.zanella@linaro.org> This patch rewrites wcsncat using wcslen, wcsnlen, and wmemcpy. This is similar to the optimization done on strncat by 3eb38795db and e80514b5a8. Checked on x86_64-linux-gnu. * wcsmbs/wcsncat.c (wcsncat): Rewrite using wcslen, wcsnlen, and wmemcpy. --- wcsmbs/wcsncat.c | 53 +++++++----------------------------------------- 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/wcsmbs/wcsncat.c b/wcsmbs/wcsncat.c index 65e9b226c6..cb6fe71e19 100644 --- a/wcsmbs/wcsncat.c +++ b/wcsmbs/wcsncat.c @@ -26,54 +26,15 @@ wchar_t * WCSNCAT (wchar_t *dest, const wchar_t *src, size_t n) { - wchar_t c; - wchar_t * const s = dest; + wchar_t *ret = dest; - /* Find the end of DEST. */ - do - c = *dest++; - while (c != L'\0'); + /* Find the end of dest. */ + dest += __wcslen (dest); - /* Make DEST point before next character, so we can increment - it while memory is read (wins on pipelined cpus). */ - dest -= 2; + size_t ds = __wcsnlen (src, n); - if (n >= 4) - { - size_t n4 = n >> 2; - do - { - c = *src++; - *++dest = c; - if (c == L'\0') - return s; - c = *src++; - *++dest = c; - if (c == L'\0') - return s; - c = *src++; - *++dest = c; - if (c == L'\0') - return s; - c = *src++; - *++dest = c; - if (c == L'\0') - return s; - } while (--n4 > 0); - n &= 3; - } + dest[ds] = L'\0'; + __wmemcpy (dest, src, ds); - while (n > 0) - { - c = *src++; - *++dest = c; - if (c == L'\0') - return s; - n--; - } - - if (c != L'\0') - *++dest = L'\0'; - - return s; + return ret; }