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

Unified Diff: src/objects.cc

Issue 6991007: Don't flatten every time we call CharCodeAt Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Handle flat cons string. Flatten entire string. Created 9 years, 7 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 | « src/objects.h ('k') | src/objects-inl.h » ('j') | src/objects-inl.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 724a734a2145d6b682725a6b9b7e9d5b7c2f26af..00b391edcb7963a3e78202c9d569b4b45e0e5fc5 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -5182,7 +5182,7 @@ uint16_t ConsString::ConsStringGet(int index) {
// Check for a flattened cons string
if (second()->length() == 0) {
String* left = first();
- return left->Get(index);
+ return FlatString::cast(left)->FlatStringGet(index);
}
String* string = String::cast(this);
@@ -5198,7 +5198,7 @@ uint16_t ConsString::ConsStringGet(int index) {
string = cons_string->second();
}
} else {
- return string->Get(index);
+ return FlatString::cast(string)->FlatStringGet(index);
}
}
@@ -5207,6 +5207,44 @@ uint16_t ConsString::ConsStringGet(int index) {
}
+MaybeObject* ConsString::ConsStringGetMayFlatten(int index) {
+ ASSERT(index >= 0);
+ ASSERT(index < this->length());
+
+ String* string = this;
+ if (this->GetIsolate()->ShouldFlattenString()) {
+ MaybeObject* flatten_result = this->TryFlatten();
+ if (flatten_result->IsFailure()) return flatten_result;
+ string = String::cast(flatten_result->ToObjectUnchecked());
+ } else {
+ int recurse_limit = 7;
Vitaly Repeshko 2011/05/12 15:54:53 Make this a (documented) constant in ConsString.
+ String* cursor = string;
+ int index_in_cursor = index;
+ while (cursor->IsConsString()) {
+ ConsString* cons = ConsString::cast(cursor);
+ String* first = cons->first();
+ int first_length = first->length();
+ if (index_in_cursor < first_length) {
+ cursor = first;
+ } else {
+ cursor = cons->second();
+ index_in_cursor -= first_length;
+ }
+ if (--recurse_limit <= 0) {
+ MaybeObject* flatten_result = this->TryFlatten();
+ if (flatten_result->IsFailure()) return flatten_result;
+ cursor = String::cast(flatten_result->ToObjectUnchecked());
Vitaly Repeshko 2011/05/12 15:54:53 It's more straightforward to simply return Smi::F
+ index_in_cursor = index;
+ break;
+ }
+ }
+ string = cursor;
+ index = index_in_cursor;
+ }
+ return Smi::FromInt(string->Get(index));
+}
+
+
template <typename sinkchar>
void String::WriteToFlat(String* src,
sinkchar* sink,
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | src/objects-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698