mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 04:45:45 +00:00
Bug 1371215 part 2 - Remove FirstCharMatcher16bit as it's not used much and has some perf issues. r=luke
This commit is contained in:
parent
20be2e7edb
commit
29ea196af6
@ -1633,52 +1633,6 @@ FirstCharMatcher8bit(const char* text, uint32_t n, const char pat)
|
||||
return reinterpret_cast<const char*>(memchr(text, pat, n));
|
||||
}
|
||||
|
||||
static const char16_t*
|
||||
FirstCharMatcher16bit(const char16_t* text, uint32_t n, const char16_t pat)
|
||||
{
|
||||
#if defined(XP_DARWIN) || defined(XP_WIN)
|
||||
/*
|
||||
* Performance of memchr is horrible in OSX. Windows is better,
|
||||
* but it is still better to use UnrolledMatcher.
|
||||
*/
|
||||
return FirstCharMatcherUnrolled<char16_t, char16_t>(text, n, pat);
|
||||
#else
|
||||
/*
|
||||
* For linux the best performance is obtained by slightly hacking memchr.
|
||||
* memchr works only on 8bit char but char16_t is 16bit. So we treat char16_t
|
||||
* in blocks of 8bit and use memchr.
|
||||
*/
|
||||
|
||||
const char* text8 = (const char*) text;
|
||||
const char* pat8 = reinterpret_cast<const char*>(&pat);
|
||||
|
||||
MOZ_ASSERT(n < UINT32_MAX/2);
|
||||
n *= 2;
|
||||
|
||||
uint32_t i = 0;
|
||||
while (i < n) {
|
||||
/* Find the first 8 bits of 16bit character in text. */
|
||||
const char* pos8 = FirstCharMatcher8bit(text8 + i, n - i, pat8[0]);
|
||||
if (pos8 == nullptr)
|
||||
return nullptr;
|
||||
i = static_cast<uint32_t>(pos8 - text8);
|
||||
|
||||
/* Incorrect match if it matches the last 8 bits of 16bit char. */
|
||||
if (i % 2 != 0) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Test if last 8 bits match last 8 bits of 16bit char. */
|
||||
if (pat8[1] == text8[i + 1])
|
||||
return (text + (i/2));
|
||||
|
||||
i += 2;
|
||||
}
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class InnerMatch, typename TextChar, typename PatChar>
|
||||
static int
|
||||
Matcher(const TextChar* text, uint32_t textlen, const PatChar* pat, uint32_t patlen)
|
||||
@ -1690,9 +1644,7 @@ Matcher(const TextChar* text, uint32_t textlen, const PatChar* pat, uint32_t pat
|
||||
while (i < n) {
|
||||
const TextChar* pos;
|
||||
|
||||
if (sizeof(TextChar) == 2 && sizeof(PatChar) == 2)
|
||||
pos = (TextChar*) FirstCharMatcher16bit((char16_t*)text + i, n - i, pat[0]);
|
||||
else if (sizeof(TextChar) == 1 && sizeof(PatChar) == 1)
|
||||
if (sizeof(TextChar) == 1 && sizeof(PatChar) == 1)
|
||||
pos = (TextChar*) FirstCharMatcher8bit((char*) text + i, n - i, pat[0]);
|
||||
else
|
||||
pos = (TextChar*) FirstCharMatcherUnrolled<TextChar, PatChar>(text + i, n - i, pat[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user