From patchwork Wed Feb 6 14:58:45 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: 157622 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6507020jaa; Wed, 6 Feb 2019 06:59:16 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib/rMvZjywD7HyxnTCuPImL5/brg52HUbiT/cKMhTRmcSTAH0SGHQKcHzTnjGJ7rKKv32bt X-Received: by 2002:a62:2a4b:: with SMTP id q72mr10794363pfq.61.1549465156785; Wed, 06 Feb 2019 06:59:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549465156; cv=none; d=google.com; s=arc-20160816; b=kp/ObjhdS0UT70YATZDpP96h4T8tFwM7itFcDQRGUzbSghrYmv1w1a5OZPYnzz9JEw L9Xpe4nRWA1DzIHJ53jeVOlh2HnEfOfF2no0oj4hloKwuFn2pPrETfyoSIqNWQUE/rIT rmmEdX91PcqqYFOMhTWq71b6yYm0tCW6oHMNlgrROsq9oU98981LeIfzJAAY4opCuxX1 1CYxNV4A4aHHEEeBEwNLgPkC7B3G1wgz83IprUb99HAEbqT5axHEE+WGcFXDLSJD7bcn fXbbpuHvIPKNQht1eEoRZhG4s9KzsBFveqOoGESg3GMPbvndKZbG/9f8/OR+uTxNhATc OZGQ== 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=xkf+5KH5Asn8C6vLg9IFSmnYDBF6qQpn6Ef0WM/jU5k=; b=aDnmiRmHjwS1/RImx41Ditzsf/IIEx3dtFC5/YEV3dUN8aMojZc04XXuV4YgZwtNIJ aoSeztnaCXhZjUWUoyi89YaiNs6ibN66jW/wzLjJTtRBCr8XShQk4dWRE9HLdeDOBpq7 Dx8fsRRiJTY4n0mZvm+tSOsynLhk097WrCJYF8KDoX+TP61x+6Pqe/zaAV8CrJ/810/T s20AxxQJMcOvs9Wdy6ul5LvP4NZ5wpi1BNjikhF/zQX0RPntlx4T71xIQy9Vi1kKH2Vh cXWKZQ32K0N83PlUH+wyzA0ZWW0f1J+NJsgvD7In2sFuPsYMeRJ4EdK8XtCAEkqjec+H lh2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=TwSJ93X6; dkim=pass header.i=@linaro.org header.s=google header.b="EpJ+oH5/"; spf=pass (google.com: domain of libc-alpha-return-99816-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99816-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 l96si805851plb.292.2019.02.06.06.59.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 06:59:16 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-99816-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=TwSJ93X6; dkim=pass header.i=@linaro.org header.s=google header.b="EpJ+oH5/"; spf=pass (google.com: domain of libc-alpha-return-99816-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-99816-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=bf00S+leBCfIwWrIKoLHu3oZ2s733c8 DctEddM9hW95HoXSVUZQ8MfjtOHICl5Km3ZClItlo5IUDAPy5KaVzkhzCQ2VtmKQ BQaJn9ZKDJKEdC5kvSOop477TJOYKlJiRBRCmpcQpmjAbnh8IG3w7gJyJlk7HLmO FvTLeSDZF5Xc= 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=tSND/M1JSaNr7jXMqbmHeqzt6jM=; b=TwSJ9 3X6dpJr94tNFqbaigO3MZp1YKvz9y2aP42Fmt/4szl6FRdb97KxyBV0Bf7meSp81 eQdWfM4u9DBJxWslXhG9w5FhoHUEouGyfalK9vG++ui80c+X0/uvfqDzLiqxzO7X BMy83PmmfnI41NknpAHiAoWQnCGvTtXAIxqLIs= Received: (qmail 109131 invoked by alias); 6 Feb 2019 14:59:00 -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 109068 invoked by uid 89); 6 Feb 2019 14:58:59 -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, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt1-f196.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=xkf+5KH5Asn8C6vLg9IFSmnYDBF6qQpn6Ef0WM/jU5k=; b=EpJ+oH5/uhPkNc7O1KIzcA5EiPcH8Zdq76JVIvOYye8llMV3vCO8ZIAJaan5BeTBfI olatzOxMw7A69PgBnBlOTWmWMTw8Ti2D09cARp/qh3jVKxqO8YEkNdsQ2lT5be6Va20D +ZEuPexWzCmtceCVw+tgAAx3mYuHGH/8PbWPo80daqxucjmtYfnR6/p1TK8bmx3MvrHM AJB9f/4c/AOS+ryQ9h+Bs/TiZbpggie7zCYbx92lOz4t6e5Z84qTHjikKtZkLuzrND0h 48RRP5DGDqHYcR73dzgcp0/TZzM/n1oDQYxB15A75RLF8v/NcXuUlvX/qWEkl7MOtsqj zURQ== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 2/7] wcsmbs: optimize wcpncpy Date: Wed, 6 Feb 2019 12:58:45 -0200 Message-Id: <20190206145850.22003-2-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 wcpncpy using wcslen, wmemcpy, and wmemset. This is similar to the optimization done on stpncpy by 48497aba8e. Checked on x86_64-linux-gnu. * wcsmbs/wcpncpy.c (__wcpcpy): Rewrite using wcslen, wmemcpy, and wmemset. --- wcsmbs/wcpncpy.c | 58 +++++------------------------------------------- 1 file changed, 6 insertions(+), 52 deletions(-) -- 2.17.1 diff --git a/wcsmbs/wcpncpy.c b/wcsmbs/wcpncpy.c index 7568f3b11c..7147affdd5 100644 --- a/wcsmbs/wcpncpy.c +++ b/wcsmbs/wcpncpy.c @@ -17,6 +17,7 @@ . */ #include +#include #ifdef WCPNCPY # define __wcpncpy WCPNCPY @@ -27,59 +28,12 @@ wchar_t * __wcpncpy (wchar_t *dest, const wchar_t *src, size_t n) { - wint_t c; - wchar_t *const s = 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 -= dest - s; - goto zero_fill; - } - - last_chars: - n &= 3; - if (n == 0) + size_t size = __wcsnlen (src, n); + __wmemcpy (dest, src, size); + dest += size; + if (size == n) return dest; - - for (;;) - { - c = *src++; - --n; - *dest++ = c; - if (c == L'\0') - break; - if (n == 0) - return dest; - } - - zero_fill: - while (n-- > 0) - dest[n] = L'\0'; - - return dest - 1; + return wmemset (dest, L'\0', (n - size)); } #ifndef WCPNCPY