From patchwork Wed May 13 10:04:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ondrej Bilka X-Patchwork-Id: 6692 Received: (qmail 66738 invoked by alias); 13 May 2015 10:04:19 -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 66665 invoked by uid 89); 13 May 2015 10:04:18 -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: Wed, 13 May 2015 12:04:02 +0200 From: =?utf-8?B?T25kxZllaiBCw61sa2E=?= To: libc-alpha@sourceware.org Subject: Re: [PATCH 2/3] Use strdiff in strcasecmp. Message-ID: <20150513100402.GA1051@domone> References: <20150513085810.GA31782@domone> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150513085810.GA31782@domone> User-Agent: Mutt/1.5.20 (2009-06-14) Hi, this optimizes strcasecmp to look for first mismatch which would likely fail in caseless case. We don't have to handle encoding as comparison is done bytewise. Is this ok? Now there isn't performance improvement as strdiff isn't yet optimized. I will add optimized strdiff in next patch. * string/strcasecmp.c (__strcasecmp): Use strdiff. diff --git a/string/strcasecmp.c b/string/strcasecmp.c index 6b14912..5d1e27e 100644 --- a/string/strcasecmp.c +++ b/string/strcasecmp.c @@ -41,6 +41,10 @@ # define LOCALE_PARAM_DECL #endif +#define STRING_TYPE char +#define USTRING_TYPE unsigned char +#include + /* Compare S1 and S2, ignoring case, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. */ @@ -53,12 +57,13 @@ __strcasecmp (s1, s2 LOCALE_PARAM) #if defined _LIBC && !defined USE_IN_EXTENDED_LOCALE_MODEL __locale_t loc = _NL_CURRENT_LOCALE; #endif + + STRDIFF_L (&s1, &s2, __cet_8bit); + const unsigned char *p1 = (const unsigned char *) s1; const unsigned char *p2 = (const unsigned char *) s2; int result; - if (p1 == p2) - return 0; while ((result = TOLOWER (*p1) - TOLOWER (*p2++)) == 0) if (*p1++ == '\0')