bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 0/5] Speed up uNN_chr and uNN_strchr with Boyer-Moore algo


From: Paolo Bonzini
Subject: Re: [PATCH v2 0/5] Speed up uNN_chr and uNN_strchr with Boyer-Moore algorithm
Date: Thu, 29 Jul 2010 18:07:01 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100621 Fedora/3.0.5-1.fc13 Lightning/1.0b2pre Thunderbird/3.0.5

On 07/29/2010 06:00 PM, Pádraig Brady wrote:
On 29/07/10 16:29, Paolo Bonzini wrote:
   if (!needle[0])
     return haystack;

   n = u8_mbtouc(&uc, needle, 4);
          ^^^^^^^^^

u8_strmbtouc here as suggested by Bruno. u8_strmbtouc also checks itself for NULL, and returns zero in that case.

   if (uc == 0xfffd&&  n != 3)
     return NULL; /* invalid, cannot be incomplete since we pass n=4 */
   if (needle[n])
     return strstr(haystack, needle);
   else
     return u8_strchr(haystack, uc); /* inlining would avoid uctomb */

Clever. I missed the 'if (needle[n])' trick.
Extra clever if the compiler actually avoids the uctomb.

Unfortunately that would be _manual_ inlining, or some #include trick to share the code between u8_strchr and u8_strstr.

I guess Bruno's point is u8_mbtouc is free to access
the given size in future, if it was changed to vectorize for example.

Right. Then we should convince him to change the spec before it's too late. :)

Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]