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: 157625 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6507380jaa; Wed, 6 Feb 2019 06:59:42 -0800 (PST) X-Google-Smtp-Source: AHgI3IajFwumuaOVL99iYTgLlxGKz8IKX70LDcoV9zd+5M+f7Rbo8nm8a2xqquXLE1PFojc4RV5p X-Received: by 2002:a17:902:968d:: with SMTP id n13mr11205048plp.109.1549465182166; Wed, 06 Feb 2019 06:59:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549465182; cv=none; d=google.com; s=arc-20160816; b=tKYuB1X0P3G13wdSuDyrOjbX24dahwDiXJ+ArQv7IoRx1WF01zpCFciqEFN+iWB4+/ /8TqJf2Dp/r++vicChpWST+e62VXvKmEnG2URjcRnunE5T8m3sqplrNoGnTmcfQpbh0s xXNNJ9A1G6sV+40/tCKessD/t3D2yRaC9jhfqq4sSgonEeW+SlCQP1FquuPevxRROSaw JOkLwS1G3A9397ZIeEDq+JbtjNH5sDxdHIjpK0tX2iGlCcOp5dXJ8yX/vs+3Q2DBTZWs 0giRk8FDKhaOtP6NqB5zSzB4aQSKNXwlDDIBUoK4mkLFZ8m4Ta80Zuj6c/360FMTRim6 aSww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=20SJ21tlZpNhS1XJTfqXZ9f9nW5s8hKP6KYDk0x+OEA=; b=1D3Tb6XdtC7ieeVj9Nutnvdt8+dBQ8eUx5edpPcFqs0kXJ+kVErS4PyN+ucFuWw49+ QPv1tFG0xr1eKG8suhd02MaTN/3SYosNPigW6SfK2nG2H01J/8isNywPdDw/Vmg0aFt7 1foiybvXGERnKn1/BhBwaVqZOaQrQBohiRI29VcBoZotz1CCBGmFT1A3Lc8ATh0FbtaN 8Kza/bTtjbNOq3QdaDQ+9/5YtheLJXNilHBkyiwJkhE0tHBm5a4FAadOfqVQOlzSmlen lbHZc0fT2MpD5aiVEDvIcnv/J/rinMWBl06OVs7H9tuSLZvqzLSffuUOlZUgkRzywWTg zcZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=XAYQQzbo; dkim=pass header.i=@linaro.org header.s=google header.b=CWqzzSOC; spf=pass (google.com: domain of libc-alpha-return-99819-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99819-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id l94si6622463plb.209.2019.02.06.06.59.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 06:59:42 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-99819-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=XAYQQzbo; dkim=pass header.i=@linaro.org header.s=google header.b=CWqzzSOC; spf=pass (google.com: domain of libc-alpha-return-99819-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99819-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=bOkAnvmlEJSCnlky66sXVGZZRwNllhV ptOFB0rGtwv1Coz59ZGw2R5TFlgCF249zcVrh8qJzx5E5BFGbaWi073xBQw4KVnW xkxsLy4LiroF7PNzcSw95/K94SSkGJsAWY41Ef7mBioSJGUn8kSHGDDiXguhQVJa slMozADcHOsY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=kO8xg6uwqo2WvJA+wiMPGdd+h0Y=; b=XAYQQ zboEQy2LHpFI3xMxDtj78j9M0T4ViDTvzjGAAj932Kop8tzgzcaVS1yIRwi1jdVh C7Gprp8F+wez3yqPDBasFEWCNb3eVBST0i35HeRjieH6yb7Aac8LkoGFnyaJt5Qd RLRqGRlyYNpBwmuvptpFnlAnSlRBjSVu9GQrvQ= 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(-) -- 2.17.1 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; }