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

Unified Diff: src/objects.cc

Issue 7477045: Tentative implementation of string slices (hidden under the flag --string-slices). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 5 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
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index a423ae4c25df2caaff6ade6de2f2684f94286522..3ffd6898103c91e863896c324f04d217b8be9c1b 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -1169,6 +1169,9 @@ void HeapObject::IterateBody(InstanceType type, int object_size,
case kConsStringTag:
ConsString::BodyDescriptor::IterateBody(this, v);
break;
+ case kSlicedStringTag:
+ SlicedString::BodyDescriptor::IterateBody(this, v);
+ break;
case kExternalStringTag:
if ((type & kStringEncodingMask) == kAsciiStringTag) {
reinterpret_cast<ExternalAsciiString*>(this)->
@@ -5246,14 +5249,21 @@ Vector<const char> String::ToAsciiVector() {
string = cons->first();
string_tag = StringShape(string).representation_tag();
}
- if (string_tag == kSeqStringTag) {
- SeqAsciiString* seq = SeqAsciiString::cast(string);
- char* start = seq->GetChars();
+ if (string_tag == kExternalStringTag) {
+ // Note that a sliced string cannot contain an external string.
+ ExternalAsciiString* ext = ExternalAsciiString::cast(string);
+ const char* start = ext->resource()->data();
return Vector<const char>(start + offset, length);
}
- ASSERT(string_tag == kExternalStringTag);
- ExternalAsciiString* ext = ExternalAsciiString::cast(string);
- const char* start = ext->resource()->data();
+ if (string_tag == kSlicedStringTag) {
+ SlicedString* slice = SlicedString::cast(string);
+ offset = slice->offset();
+ string = slice->parent();
+ string_tag = StringShape(string).representation_tag();
+ }
+ ASSERT(string_tag == kSeqStringTag);
+ SeqAsciiString* seq = SeqAsciiString::cast(string);
+ char* start = seq->GetChars();
return Vector<const char>(start + offset, length);
}
@@ -5272,15 +5282,22 @@ Vector<const uc16> String::ToUC16Vector() {
string = cons->first();
string_tag = StringShape(string).representation_tag();
}
- if (string_tag == kSeqStringTag) {
- SeqTwoByteString* seq = SeqTwoByteString::cast(string);
- return Vector<const uc16>(seq->GetChars() + offset, length);
+ if (string_tag == kExternalStringTag) {
+ // Note that a sliced string cannot contain an external string.
+ ExternalTwoByteString* ext = ExternalTwoByteString::cast(string);
+ const uc16* start =
+ reinterpret_cast<const uc16*>(ext->resource()->data());
+ return Vector<const uc16>(start + offset, length);
+ }
+ if (string_tag == kSlicedStringTag) {
+ SlicedString* slice = SlicedString::cast(string);
+ offset = slice->offset();
+ string = slice->parent();
+ string_tag = StringShape(string).representation_tag();
}
- ASSERT(string_tag == kExternalStringTag);
- ExternalTwoByteString* ext = ExternalTwoByteString::cast(string);
- const uc16* start =
- reinterpret_cast<const uc16*>(ext->resource()->data());
- return Vector<const uc16>(start + offset, length);
+ ASSERT(string_tag == kSeqStringTag);
+ SeqTwoByteString* seq = SeqTwoByteString::cast(string);
+ return Vector<const uc16>(seq->GetChars() + offset, length);
}
@@ -5358,6 +5375,10 @@ const uc16* String::GetTwoByteData(unsigned start) {
case kExternalStringTag:
return ExternalTwoByteString::cast(this)->
ExternalTwoByteStringGetData(start);
+ case kSlicedStringTag: {
+ SlicedString* slice = SlicedString::cast(this);
+ return slice->parent()->GetTwoByteData(start + slice->offset());
+ }
case kConsStringTag:
UNREACHABLE();
return NULL;
@@ -5635,6 +5656,10 @@ const unibrow::byte* String::ReadBlock(String* input,
return ConsString::cast(input)->ConsStringReadBlock(rbb,
offset_ptr,
max_chars);
+ case kSlicedStringTag:
+ return SlicedString::cast(input)->SlicedStringReadBlock(rbb,
+ offset_ptr,
+ max_chars);
case kExternalStringTag:
if (input->IsAsciiRepresentation()) {
return ExternalAsciiString::cast(input)->ExternalAsciiStringReadBlock(
@@ -5778,6 +5803,11 @@ void String::ReadBlockIntoBuffer(String* input,
offset_ptr,
max_chars);
return;
+ case kSlicedStringTag:
+ SlicedString::cast(input)->SlicedStringReadBlockIntoBuffer(rbb,
+ offset_ptr,
+ max_chars);
+ return;
case kExternalStringTag:
if (input->IsAsciiRepresentation()) {
ExternalAsciiString::cast(input)->
@@ -5923,6 +5953,31 @@ uint16_t ConsString::ConsStringGet(int index) {
}
+uint16_t SlicedString::SlicedStringGet(int index) {
+ return parent()->Get(offset() + index);
+}
+
+
+const unibrow::byte* SlicedString::SlicedStringReadBlock(
+ ReadBlockBuffer* buffer, unsigned* offset_ptr, unsigned chars) {
+ unsigned offset = this->offset();
+ *offset_ptr += offset;
+ const unibrow::byte* answer = String::ReadBlock(String::cast(parent()),
+ buffer, offset_ptr, chars);
+ *offset_ptr -= offset;
+ return answer;
+}
+
+
+void SlicedString::SlicedStringReadBlockIntoBuffer(
+ ReadBlockBuffer* buffer, unsigned* offset_ptr, unsigned chars) {
+ unsigned offset = this->offset();
+ *offset_ptr += offset;
+ String::ReadBlockIntoBuffer(String::cast(parent()),
+ buffer, offset_ptr, chars);
+ *offset_ptr -= offset;
+}
+
template <typename sinkchar>
void String::WriteToFlat(String* src,
sinkchar* sink,
@@ -5990,6 +6045,13 @@ void String::WriteToFlat(String* src,
}
break;
}
+ case kAsciiStringTag | kSlicedStringTag:
+ case kTwoByteStringTag | kSlicedStringTag: {
+ SlicedString* slice = SlicedString::cast(source);
+ unsigned offset = slice->offset();
+ WriteToFlat(slice->parent(), sink, from + offset, to + offset);
+ return;
+ }
}
}
}

Powered by Google App Engine
This is Rietveld 408576698