Use std::binary_search rather than a set in GetWordBoundaries

This is slightly faster and simpler.

Originally committed to SVN as r6612.
This commit is contained in:
Thomas Goyne 2012-03-27 00:49:15 +00:00
parent 909a0ca280
commit 1f1e9a700a
1 changed files with 18 additions and 27 deletions

View File

@ -34,14 +34,9 @@
/// @ingroup utility /// @ingroup utility
/// ///
///////////
// Headers
#include "config.h" #include "config.h"
#ifndef AGI_PRE #ifndef AGI_PRE
#include <set>
#ifdef __UNIX__ #ifdef __UNIX__
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -169,9 +164,7 @@ void GetWordBoundaries(const wxString text, IntPairVector &results, int start, i
if (end < 0) end = text.size(); if (end < 0) end = text.size();
// Delimiters // Delimiters
static std::set<wxUniChar> delims; const wxUniChar delims[] = {
if (delims.empty()) {
const wxUniChar delim_chars[] = {
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0028, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0028,
0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 0x003a, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 0x003a,
0x003b, 0x003d, 0x003f, 0x0040, 0x005b, 0x005c, 0x005d, 0x005e, 0x003b, 0x003d, 0x003f, 0x0040, 0x005b, 0x005c, 0x005d, 0x005e,
@ -188,8 +181,6 @@ void GetWordBoundaries(const wxString text, IntPairVector &results, int start, i
0x3019, 0x301a, 0x301b, 0x301c, 0x3030, 0x303d, 0x30fb, 0xff0a, 0x3019, 0x301a, 0x301b, 0x301c, 0x3030, 0x303d, 0x30fb, 0xff0a,
0xff5b, 0xff5d, 0xff5e 0xff5b, 0xff5d, 0xff5e
}; };
delims.insert(delim_chars, delim_chars + sizeof(delim_chars) / sizeof(delim_chars[0]));
}
for (int i = start; i < end + 1; ++i) { for (int i = start; i < end + 1; ++i) {
// Current character // Current character
@ -227,7 +218,7 @@ void GetWordBoundaries(const wxString text, IntPairVector &results, int start, i
i++; i++;
} }
// Check for standard delimiters // Check for standard delimiters
else if (delims.count(cur)) { else if (std::binary_search(delims, delims + sizeof(delims) / sizeof(delims[0]), cur)) {
if (start != i) if (start != i)
results.push_back(std::make_pair(start, i)); results.push_back(std::make_pair(start, i));
start = i + 1; start = i + 1;