Reviewers: Jakob, ishell,
Message:
Sorry for all the trouble. This should get the mips build bots green again.
Description:
Fix two byte string-search on big endian platforms
Use AlignDown instead of IsAligned to avoid false negatives
on big endian platforms
Use byte with highest value to speedup search
BUG=
Please review this at https://codereview.chromium.org/1324803003/
Base URL: https://chromium.googlesource.com/v8/v8.git@speedup-stringsearch
Affected files (+13, -7 lines):
M src/string-search.h
Index: src/string-search.h
diff --git a/src/string-search.h b/src/string-search.h
index
e2e540b6cf8324f573a451b5061ebfd92ede1857..2337841174d50e1321b8000fd145ac0b197248cc
100644
--- a/src/string-search.h
+++ b/src/string-search.h
@@ -190,6 +190,13 @@ class StringSearch : private StringSearchBase {
};
+template <typename T, typename U>
+inline T AlignDown(T value, U alignment) {
+ return reinterpret_cast<T>(
+ (reinterpret_cast<uintptr_t>(value) & ~(alignment - 1)));
+}
+
+
template <typename PatternChar, typename SubjectChar>
int FindFirstCharacter(Vector<const PatternChar> pattern,
Vector<const SubjectChar> subject, int index) {
@@ -203,22 +210,21 @@ int FindFirstCharacter(Vector<const PatternChar>
pattern,
if (char_pos == NULL) return -1;
return static_cast<int>(char_pos - subject.start());
} else {
- const uint8_t search_low_byte =
- static_cast<uint8_t>(pattern_first_char & 0xFF);
+ const uint8_t search_byte =
+ Max(static_cast<uint8_t>(pattern_first_char & 0xFF),
+ static_cast<uint8_t>(pattern_first_char >> 8));
const SubjectChar search_char =
static_cast<SubjectChar>(pattern_first_char);
int pos = index;
do {
DCHECK_GE(max_n - pos, 0);
const SubjectChar* char_pos = reinterpret_cast<const SubjectChar*>(
- memchr(subject.start() + pos, search_low_byte,
+ memchr(subject.start() + pos, search_byte,
(max_n - pos) * sizeof(SubjectChar)));
if (char_pos == NULL) return -1;
+ char_pos = AlignDown(char_pos, sizeof(SubjectChar));
pos = static_cast<int>(char_pos - subject.start());
- if (IsAligned(reinterpret_cast<uintptr_t>(char_pos),
- sizeof(SubjectChar))) {
- if (subject[pos] == search_char) return pos;
- }
+ if (subject[pos] == search_char) return pos;
} while (++pos < max_n);
}
return -1;
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.