Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: src/runtime.cc

Issue 7300: * StringSearch now tests aginst non-ascii needle on an ascii string as the first thing. (Closed)
Patch Set: Rebase to SVN version Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index c7cbb1bd42381ee127b55ab0473e06d0c6c1286c..b094307519d1ed62363ea094c55d9972164b3e09 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -996,8 +996,8 @@ static BMGoodSuffixBuffers bmgs_buffers;
// Compute the bad-char table for Boyer-Moore in the static buffer.
// Return false if the pattern contains non-ASCII characters that cannot be
// in the searched string.
-template <typename pchar, bool check_ascii>
-static bool BoyerMoorePopulateBadCharTable(Vector<const pchar> pattern,
+template <typename pchar>
+static void BoyerMoorePopulateBadCharTable(Vector<const pchar> pattern,
int start) {
// Run forwards to populate bad_char_table, so that *last* instance
// of character equivalence class is the one registered.
@@ -1006,14 +1006,8 @@ static bool BoyerMoorePopulateBadCharTable(Vector<const pchar> pattern,
bad_char_occurence[i] = start - 1;
}
for (int i = start; i < pattern.length(); i++) {
- uc32 c = pattern[i];
- bad_char_occurence[c % kBMAlphabetSize] = i;
- if (check_ascii &&
- c > String::kMaxAsciiCharCode) {
- return false;
- }
+ bad_char_occurence[pattern[i] % kBMAlphabetSize] = i;
}
- return true;
}
template <typename pchar>
@@ -1081,13 +1075,7 @@ static int BoyerMooreIndexOf(Vector<const schar> subject,
int start = m < kBMMaxShift ? 0 : m - kBMMaxShift;
int len = m - start;
- if (sizeof(pchar) > 1 && sizeof(schar) == 1) {
- BoyerMoorePopulateBadCharTable<pchar, true>(pattern, start);
- } else {
- if (!BoyerMoorePopulateBadCharTable<pchar, false>(pattern, start)) {
- return -1;
- }
- }
+ BoyerMoorePopulateBadCharTable(pattern, start);
int badness = 0; // How bad we are doing without a good-suffix table.
int idx; // No matches found prior to this index.
@@ -1201,6 +1189,17 @@ static int StringMatchStrategy(Vector<const schar> sub,
int start_index) {
ASSERT(pat.length() > 1);
+ // We have an ASCII haystack and a non-ASCII needle. Check if there
+ // really is a non-ASCII character in the needle and bail out if there
+ // is.
+ if (sizeof(pchar) > 1 && sizeof(schar) == 1) {
+ for (int i = 0; i < pat.length(); i++) {
+ uc16 c = pat[i];
+ if (c > String::kMaxAsciiCharCode) {
+ return -1;
+ }
+ }
+ }
// For small searches, a complex sort is not worth the setup overhead.
bool complete;
int idx = SimpleIndexOf(sub, pat, start_index, complete);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698