Reviewers: dcarney, marja,

Message:
PTAL. I didn't go with GetFlatContent of a string because it is too generic. It
checks for (sliced/seq/ext)*(one/two byte). Instead, I make sure that only
seq/ext strings are stored in SubStringKey. Since the char type is a template,
this requires only one comparison for dispatch in IsMatch.

Description:
Experimental lexer: add handling of sliced strings in SubStringKey

BUG=

Please review this at https://codereview.chromium.org/143303002/

SVN Base: https://v8.googlecode.com/svn/branches/experimental/parser

Affected files (+14, -1 lines):
  M src/objects-inl.h


Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 73fc0a6b71ff1912188bc1c4e05f73931294bee3..3f59581f3be60a357d4a5566f26312f4e83fc464 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -503,7 +503,12 @@ template<class Char>
 class SubStringKey : public HashTableKey {
  public:
   SubStringKey(Handle<String> string, int from, int length)
-      : string_(string), from_(from), length_(length) { }
+      : string_(string), from_(from), length_(length) {
+    if (string_->IsSlicedString()) {
+      string_ = Handle<String>(Unslice(*string_, &from));
+    }
+    ASSERT(string_->IsSeqString() || string->IsExternalString());
+  }

   virtual uint32_t Hash() {
     ASSERT(length_ >= 0);
@@ -525,6 +530,14 @@ class SubStringKey : public HashTableKey {

  private:
   const Char* GetChars();
+  String* Unslice(String* string, int* offset) {
+    while (string->IsSlicedString()) {
+      SlicedString* sliced = SlicedString::cast(string);
+      *offset += sliced->offset();
+      string = sliced->parent();
+    }
+    return string;
+  }

   Handle<String> string_;
   int from_;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to