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

Unified Diff: src/runtime.cc

Issue 1100002: String search performance improvements: (Closed)
Patch Set: Created 10 years, 9 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 16164badd84de9ec3ed08b3beffebad9ebfc8c85..559bcd385765e2c5e37a1db8a82e11e7d7be03d5 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -2353,6 +2353,14 @@ template <typename schar>
static inline int SingleCharIndexOf(Vector<const schar> string,
schar pattern_char,
int start_index) {
+ if (sizeof(schar) == 1) {
+ schar* pos = reinterpret_cast<schar*>(
+ memchr(string.start() + start_index,
+ pattern_char,
+ string.length() - start_index));
+ if (pos == NULL) return -1;
+ return pos - string.start();
+ }
for (int i = start_index, n = string.length(); i < n; i++) {
if (pattern_char == string[i]) {
return i;
@@ -2400,7 +2408,18 @@ static int SimpleIndexOf(Vector<const schar> subject,
*complete = false;
return i;
}
- if (subject[i] != pattern_first_char) continue;
+ if (sizeof(schar) == 1 && sizeof(pchar) == 1) {
+ schar* pos = reinterpret_cast<schar*>(memchr(subject.start() + i,
+ pattern_first_char,
+ n - i + 1));
+ if (pos == NULL) {
+ *complete = true;
+ return -1;
+ }
+ i = pos - subject.start();
+ } else {
+ if (subject[i] != pattern_first_char) continue;
+ }
int j = 1;
do {
if (pattern[j] != subject[i+j]) {
@@ -2425,7 +2444,15 @@ static int SimpleIndexOf(Vector<const schar> subject,
int idx) {
pchar pattern_first_char = pattern[0];
for (int i = idx, n = subject.length() - pattern.length(); i <= n; i++) {
- if (subject[i] != pattern_first_char) continue;
+ if (sizeof(schar) == 1 && sizeof(pchar) == 1) {
+ schar* pos = reinterpret_cast<schar*>(memchr(subject.start() + i,
+ pattern_first_char,
+ n - i + 1));
+ if (pos == NULL) return -1;
+ i = pos - subject.start();
+ } else {
+ if (subject[i] != pattern_first_char) continue;
+ }
int j = 1;
do {
if (pattern[j] != subject[i+j]) {
« 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