|
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 15:06:14 +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 12:40 PM, Pádraig Brady wrote:
I thought of that but thought it would be too much overhead for the general case since it seemed like it would need strlen, u8_mbsnlen& u8_mbtouc, with conversions back and forth.
No! You can cheat! :) Just pass 4 to u8_mbtouc. There will be no out-of-bounds access: if the string ends before that, you get either a complete character or an EILSEQ.
The only extra check that you have to do is for an empty needle, which is not the same as u8_strchr (s, 0).
Paolo
[Prev in Thread] | Current Thread | [Next in Thread] |