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

Unified Diff: src/objects-inl.h

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
« src/objects.cc ('K') | « src/objects.cc ('k') | src/runtime.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 9a38584cba6caa8400218bacb324f369b03451bd..82ed6e568c0d956fabdd03b5c091472a99ebe459 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -178,6 +178,13 @@ bool Object::IsConsString() {
}
+bool Object::IsFlatString() {
+ if (!this->IsHeapObject()) return false;
+ uint32_t type = HeapObject::cast(this)->map()->instance_type();
Erik Corry 2011/05/11 19:31:59 Assert that the flat string enum is zero.
+ return (type & (kIsNotStringMask | kStringRepresentationMask)) == kStringTag;
+}
+
+
bool Object::IsSeqString() {
if (!IsString()) return false;
return StringShape(String::cast(this)).IsSequential();
@@ -1875,6 +1882,7 @@ CAST_ACCESSOR(CompilationCacheTable)
CAST_ACCESSOR(CodeCacheHashTable)
CAST_ACCESSOR(MapCache)
CAST_ACCESSOR(String)
+CAST_ACCESSOR(FlatString)
CAST_ACCESSOR(SeqString)
CAST_ACCESSOR(SeqAsciiString)
CAST_ACCESSOR(SeqTwoByteString)
@@ -1974,6 +1982,26 @@ String* String::TryFlattenGetString(PretenureFlag pretenure) {
}
+uint16_t FlatString::FlatStringGet(int index) {
+ ASSERT(index >= 0 && index < length());
+ switch (StringShape(this).full_representation_tag()) {
+ case kSeqStringTag | kAsciiStringTag:
+ return SeqAsciiString::cast(this)->SeqAsciiStringGet(index);
+ case kSeqStringTag | kTwoByteStringTag:
+ return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index);
+ case kExternalStringTag | kAsciiStringTag:
+ return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index);
+ case kExternalStringTag | kTwoByteStringTag:
+ return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index);
+ default:
+ break;
+ }
+
+ UNREACHABLE();
+ return 0;
+}
+
+
uint16_t String::Get(int index) {
ASSERT(index >= 0 && index < length());
switch (StringShape(this).full_representation_tag()) {
@@ -1991,12 +2019,24 @@ uint16_t String::Get(int index) {
default:
break;
}
-
UNREACHABLE();
return 0;
}
+MaybeObject* String::GetMayFlatten(int index) {
+ if (this->IsConsString()) {
+ if (this->IsFlat()) {
Erik Corry 2011/05/11 19:31:59 There is some name confusion here. Until now the
Vitaly Repeshko 2011/05/12 15:54:53 I agree that this is confusing. IsFlat is usually
+ FlatString* first = FlatString::cast(ConsString::cast(this)->first());
+ return Smi::FromInt(first->FlatStringGet(index));
+ } else {
+ return ConsString::cast(this)->ConsStringGetMayFlatten(index);
+ }
+ }
+ return Smi::FromInt(FlatString::cast(this)->FlatStringGet(index));
+}
+
+
void String::Set(int index, uint16_t value) {
ASSERT(index >= 0 && index < length());
ASSERT(StringShape(this).IsSequential());
« src/objects.cc ('K') | « src/objects.cc ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698