From patchwork Wed Feb 6 14:58:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 157626 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6507501jaa; Wed, 6 Feb 2019 06:59:50 -0800 (PST) X-Google-Smtp-Source: AHgI3IbjWttTitZze//MwwUgPv2KO1gtzEZ9nZJx47H4MlumS+OqQCBOt4qVQMZC8BxH0viRhY00 X-Received: by 2002:a63:e5d:: with SMTP id 29mr9900470pgo.237.1549465190510; Wed, 06 Feb 2019 06:59:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549465190; cv=none; d=google.com; s=arc-20160816; b=f3wsVnqnkxvEbItbP/eCif1d7x6zUdaQ9Sd9WwlbRtdTa0OA1rIk/uKou9mMqyEDXM ATFpt9n3qcCX7+sY7C4Yrwvx2QozzIQ+v2m6v3O26WrbV8UxrdfBSnexzG/ZXBkYZZuJ +bmIIzYNAFBgfFl3uUKcOrvsUOZ63SinlhbUUJJ22U9PBPX79vpxTdcwgL1sd0N/ddDd aYbJoZmsd7WV/B4sSQ4VFiGl84UEvUIx02IXUpB/uTLj4Zdj7/c2AagSAGVl3cyUuzQT M86pufC5xuZ9py6pyVkN2iZ/+WhbejHtKAaniM/oR4mjUY8Q+pY0cdhPPuipoCMZ4nwJ ClLQ== 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=V2aQ/Yu5qAsX0B4JdCgC4Jknz71S7kCZHOUeR3xT+VI=; b=I7fwvrM2pIplimLxl+712RIvtga8AwXSw2xQ84PnqcsepadyLYjYVUyaCb2zZwHEPl /HOjrY3bePhdgG3BP5teZfu1APWZAry4s7ikj/2mL4r361CqG4GuP7nE3Nt+4GIjDmZi dQykI7yeV4ZDyPCEHf7eW0cST9lJIImhEKS4Q6vJhnrRi2mXqYtsdI/57BQTE3VZ6CPi y+Fco9kkPgdGWxErNhdf4PeMThANFJGCtiwHQp7y+cK20kLJStm6B7xCJMMj9DqkWRZy cyDfGAaDpNQmI17altblPOchcwXgqYfDJLlXgxwlDQVbeNwyqvTL2P87ZcsXBzYvdAsz qYqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=s0kyn3ee; dkim=pass header.i=@linaro.org header.s=google header.b=G4lDscib; spf=pass (google.com: domain of libc-alpha-return-99820-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99820-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 a10si6019015plp.167.2019.02.06.06.59.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 06:59:50 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-99820-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=s0kyn3ee; dkim=pass header.i=@linaro.org header.s=google header.b=G4lDscib; spf=pass (google.com: domain of libc-alpha-return-99820-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99820-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=ezpXKoW21jJe6biuCeZs2xFa792xjgM exIwjs5kgzvThc3sTA2AvGEqsSCQsuZvL2GzGzx01WcpoFuejnCbe/HicwehIzLh J2burG/j2rb3h5/6vkgoSThNacLBv+rxfjhfKI9xJn/CYbdeXUCzUO+z3ajNCI3X p58cxlvtpHwA= 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=Tdvku9jR99pQcth0tNcGvfOCNFs=; b=s0kyn 3eejpSPGT5FHBJAo3XjT5yLJ+q5H0C3AFVsDU1i0Gx3RBSTDDR9hzRqpYRAXy5Kl 0LZ+pQzySiZxBCBfKCQStgM7YA15p7dT1SBaj1Bo0zDtIfy9hGxhXtFNcZp6ESgo TLv6lerOUBkTqBv4CCWVpRkJ36uOtTq4eFISjU= Received: (qmail 110078 invoked by alias); 6 Feb 2019 14:59:05 -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 110033 invoked by uid 89); 6 Feb 2019 14:59:05 -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-f176.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=V2aQ/Yu5qAsX0B4JdCgC4Jknz71S7kCZHOUeR3xT+VI=; b=G4lDscibi5Oap9jcQkCExwRahD0egGuX0I7tzaaDDj0+qndhNGsw621fLcYe0BBWjY jBOozzK4/Ik7EpHulgNPcoPzVqZbUQw5EhuWbhVp0DF8PTIHHFm54Carr4nmrRYq0Ckk 64f3GHgHx0IpSRJeFrVXo+vRTjJTcAbllK1cjnH8TFLx+RcyVqjE0DgS1wMuiUrOaBG3 WfQATJt7jiwfEvixRbJ0/tIo3pRW0mmrrNaTk3SN8kdrMXe0D4bn8Oz6OmbSWQA+pMjS 2n62EF0l9xpBArYZ/ujvlljauuGg0ia3GSplGHssM71jnhqlg8ttu4zSBNVPfabd0Db0 JXyQ== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 6/7] wcsmbs: optimize wcsncpy Date: Wed, 6 Feb 2019 12:58:49 -0200 Message-Id: <20190206145850.22003-6-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 wcsncpy using wcsnlen, wmemset, and wmemcpy. This is similar to the optimization done on strncpy by f6482cf29d and 6423d4754c. Checked on x86_64-linux-gnu. * wcsmbs/wcsncpy.c (__wcsncpy): Rewrite using wcsnlen, wmemset, and wmemcpy. --- wcsmbs/wcsncpy.c | 60 ++++-------------------------------------------- 1 file changed, 4 insertions(+), 56 deletions(-) -- 2.17.1 diff --git a/wcsmbs/wcsncpy.c b/wcsmbs/wcsncpy.c index 2fd523c815..d5d7f4ad86 100644 --- a/wcsmbs/wcsncpy.c +++ b/wcsmbs/wcsncpy.c @@ -26,62 +26,10 @@ wchar_t * __wcsncpy (wchar_t *dest, const wchar_t *src, size_t n) { - wint_t c; - wchar_t *const s = dest; - - --dest; - - if (n >= 4) - { - size_t n4 = n >> 2; - - for (;;) - { - c = *src++; - *++dest = c; - if (c == L'\0') - break; - c = *src++; - *++dest = c; - if (c == L'\0') - break; - c = *src++; - *++dest = c; - if (c == L'\0') - break; - c = *src++; - *++dest = c; - if (c == L'\0') - break; - if (--n4 == 0) - goto last_chars; - } - n = n - (dest - s) - 1; - if (n == 0) - return s; - goto zero_fill; - } - - last_chars: - n &= 3; - if (n == 0) - return s; - - do - { - c = *src++; - *++dest = c; - if (--n == 0) - return s; - } - while (c != L'\0'); - - zero_fill: - do - *++dest = L'\0'; - while (--n > 0); - - return s; + size_t size = __wcsnlen (src, n); + if (size != n) + __wmemset (dest + size, L'\0', n - size); + return __wmemcpy (dest, src, size); } #ifndef WCSNCPY weak_alias (__wcsncpy, wcsncpy)