From patchwork Sun May 24 15:40:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ondrej Bilka X-Patchwork-Id: 6906 Received: (qmail 71449 invoked by alias); 24 May 2015 15:40:36 -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 71431 invoked by uid 89); 24 May 2015 15:40:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, SPF_NEUTRAL autolearn=no version=3.3.2 X-HELO: popelka.ms.mff.cuni.cz Date: Sun, 24 May 2015 17:40:17 +0200 From: =?utf-8?B?T25kxZllaiBCw61sa2E=?= To: libc-alpha@sourceware.org Subject: Re: [PATCH 3/*] Use strchrnul for strcspn (x, "c") Message-ID: <20150524154017.GA18976@domone> References: <20150524150715.GA31589@domone> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150524150715.GA31589@domone> User-Agent: Mutt/1.5.20 (2009-06-14) A loop there is clearly suboptimal. We improve performance by using strchrnul equivalent. OK to commit? * string/bits/string2.h (__strcspn_c1): Optimize with __strchrnul. diff --git a/string/bits/string2.h b/string/bits/string2.h index a595c74..2fe67b3 100644 --- a/string/bits/string2.h +++ b/string/bits/string2.h @@ -277,10 +277,7 @@ __STRING_INLINE size_t __strcspn_c1 (const char *__s, int __reject); __STRING_INLINE size_t __strcspn_c1 (const char *__s, int __reject) { - size_t __result = 0; - while (__s[__result] != '\0' && __s[__result] != __reject) - ++__result; - return __result; + return __strchrnul (__s, __reject) - __s; } __STRING_INLINE size_t __strcspn_c2 (const char *__s, int __reject1,