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

Unified Diff: src/objects-inl.h

Issue 2549773002: Internalize strings in-place (Closed)
Patch Set: forgot one Created 4 years 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/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index bfed673c9d83d1e5fa5ddec7cddde2ba6646aa74..93b1ae835eda391c9cc24680f5d0fda769b1e7f7 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -227,6 +227,11 @@ bool HeapObject::IsConsString() const {
return StringShape(String::cast(this)).IsCons();
}
+bool HeapObject::IsThinString() const {
+ if (!IsString()) return false;
+ return StringShape(String::cast(this)).IsThin();
+}
+
bool HeapObject::IsSlicedString() const {
if (!IsString()) return false;
return StringShape(String::cast(this)).IsSliced();
@@ -421,6 +426,9 @@ bool StringShape::IsSliced() {
return (type_ & kStringRepresentationMask) == kSlicedStringTag;
}
+bool StringShape::IsThin() {
+ return (type_ & kStringRepresentationMask) == kThinStringTag;
+}
bool StringShape::IsIndirect() {
return (type_ & kIsIndirectStringMask) == kIsIndirectStringTag;
@@ -3389,6 +3397,7 @@ CAST_ACCESSOR(StringTable)
CAST_ACCESSOR(Struct)
CAST_ACCESSOR(Symbol)
CAST_ACCESSOR(TemplateInfo)
+CAST_ACCESSOR(ThinString)
CAST_ACCESSOR(Uint16x8)
CAST_ACCESSOR(Uint32x4)
CAST_ACCESSOR(Uint8x16)
@@ -3749,6 +3758,9 @@ bool String::Equals(Handle<String> one, Handle<String> two) {
Handle<String> String::Flatten(Handle<String> string, PretenureFlag pretenure) {
+ if (string->IsThinString()) {
+ return handle(Handle<ThinString>::cast(string)->actual());
+ }
if (!string->IsConsString()) return string;
Handle<ConsString> cons = Handle<ConsString>::cast(string);
if (cons->IsFlat()) return handle(cons->first());
@@ -3773,6 +3785,9 @@ uint16_t String::Get(int index) {
case kSlicedStringTag | kOneByteStringTag:
case kSlicedStringTag | kTwoByteStringTag:
return SlicedString::cast(this)->SlicedStringGet(index);
+ case kThinStringTag | kOneByteStringTag:
+ case kThinStringTag | kTwoByteStringTag:
+ return ThinString::cast(this)->ThinStringGet(index);
default:
break;
}
@@ -3804,6 +3819,7 @@ String* String::GetUnderlying() {
DCHECK(this->IsFlat());
DCHECK(StringShape(this).IsIndirect());
STATIC_ASSERT(ConsString::kFirstOffset == SlicedString::kParentOffset);
+ STATIC_ASSERT(ConsString::kFirstOffset == ThinString::kActualOffset);
const int kUnderlyingOffset = SlicedString::kParentOffset;
return String::cast(READ_FIELD(this, kUnderlyingOffset));
}
@@ -3855,6 +3871,11 @@ ConsString* String::VisitFlat(Visitor* visitor,
case kConsStringTag | kTwoByteStringTag:
return ConsString::cast(string);
+ case kThinStringTag | kOneByteStringTag:
+ case kThinStringTag | kTwoByteStringTag:
+ string = ThinString::cast(string)->actual();
+ continue;
+
default:
UNREACHABLE();
return NULL;
@@ -3980,6 +4001,7 @@ void ConsString::set_second(String* value, WriteBarrierMode mode) {
CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kSecondOffset, value, mode);
}
+ACCESSORS(ThinString, actual, String, kActualOffset);
bool ExternalString::is_short() {
InstanceType type = map()->instance_type();
« src/objects-debug.cc ('K') | « src/objects-debug.cc ('k') | src/objects-printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698