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