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

Unified Diff: src/runtime.cc

Issue 11299163: Optimize non-ASCII string splitting with single-character search pattern (Closed)
Patch Set: Created 8 years, 1 month 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
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index a15e1f50539de0b18ac3d4526f83d63cb1076eb5..ba41459d02707ef4ec1ee43a4aeaac0fe27f9ed4 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -2762,6 +2762,23 @@ void FindAsciiStringIndices(Vector<const char> subject,
}
+void FindTwoByteStringIndices(const Vector<const uc16> subject,
+ uc16 pattern,
+ ZoneList<int>* indices,
+ unsigned int limit,
+ Zone* zone) {
+ ASSERT(limit > 0);
+ const uc16* subject_start = subject.start();
+ const uc16* subject_end = subject_start + subject.length();
+ for (const uc16* pos = subject_start; pos < subject_end && limit > 0; pos++) {
+ if (*pos == pattern) {
+ indices->Add(static_cast<int>(pos - subject_start), zone);
+ limit--;
+ }
+ }
+}
+
+
template <typename SubjectChar, typename PatternChar>
void FindStringIndices(Isolate* isolate,
Vector<const SubjectChar> subject,
@@ -2825,13 +2842,22 @@ void FindStringIndicesDispatch(Isolate* isolate,
}
} else {
Vector<const uc16> subject_vector = subject_content.ToUC16Vector();
- if (pattern_content.IsAscii()) {
- FindStringIndices(isolate,
- subject_vector,
- pattern_content.ToAsciiVector(),
- indices,
- limit,
- zone);
+ if (pattern_content.Length() == 1) {
+ uc16 pattern_char = pattern_content.IsAscii() ?
+ pattern_content.ToAsciiVector()[0] :
+ pattern_content.ToUC16Vector()[0];
+ FindTwoByteStringIndices(subject_vector,
+ pattern_char,
+ indices,
+ limit,
+ zone);
+ } else if (pattern_content.IsAscii()) {
+ FindStringIndices(isolate,
+ subject_vector,
+ pattern_content.ToAsciiVector(),
+ indices,
+ limit,
+ zone);
Yang 2012/11/26 08:45:30 Since we are doing the IsAscii() check (implied in
} else {
FindStringIndices(isolate,
subject_vector,
« src/objects.h ('K') | « src/objects.h ('k') | test/mjsunit/string-split.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698