Reviewers: dcarney, Sven Panne,
Message:
PTAL. This is a cherry-pick from experimental lexer.
Description:
Generalize internalization of substrings.
Make a template version of SubStringKey, which allows internalization of
substrings of sequential and external strings.
[email protected],[email protected]
Please review this at https://codereview.chromium.org/143223004/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+66, -20 lines):
M src/factory.h
M src/factory.cc
M src/objects-inl.h
M src/objects.cc
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index
65888acbf00d48974464a5e2872b04f078360f0a..1402f1de402eb3f706e0f2ad76c0848fe3979955
100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -227,7 +227,7 @@ Handle<String>
Factory::InternalizeOneByteString(Vector<const uint8_t> string) {
Handle<String> Factory::InternalizeOneByteString(
Handle<SeqOneByteString> string, int from, int length) {
- SubStringOneByteStringKey key(string, from, length);
+ SubStringKey<uint8_t> key(string, from, length);
return InternalizeStringWithKey(&key);
}
@@ -246,6 +246,12 @@ Handle<String>
Factory::InternalizeStringWithKey(StringTableKey* key) {
}
+template Handle<String> Factory::InternalizeStringWithKey<
+ SubStringKey<uint8_t> > (SubStringKey<uint8_t>* key);
+template Handle<String> Factory::InternalizeStringWithKey<
+ SubStringKey<uint16_t> > (SubStringKey<uint16_t>* key);
+
+
Handle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
PretenureFlag pretenure) {
CALL_HEAP_FUNCTION(
Index: src/factory.h
diff --git a/src/factory.h b/src/factory.h
index
8ca9d481d805da40e4e7ca510bf9686bae9518aa..db25b09a91e7629e02c56fa1a94b07380c39b8b7
100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -99,9 +99,9 @@ class Factory {
}
Handle<String> InternalizeString(Handle<String> str);
Handle<String> InternalizeOneByteString(Vector<const uint8_t> str);
- Handle<String> InternalizeOneByteString(Handle<SeqOneByteString>,
- int from,
- int length);
+ Handle<String> InternalizeOneByteString(
+ Handle<SeqOneByteString>, int from, int length);
+
Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
template<class StringTableKey>
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index
fb996a219e28df171504916345c496394ab4c3c1..73fc0a6b71ff1912188bc1c4e05f73931294bee3
100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -499,17 +499,16 @@ class OneByteStringKey : public
SequentialStringKey<uint8_t> {
};
-class SubStringOneByteStringKey : public HashTableKey {
+template<class Char>
+class SubStringKey : public HashTableKey {
public:
- explicit SubStringOneByteStringKey(Handle<SeqOneByteString> string,
- int from,
- int length)
+ SubStringKey(Handle<String> string, int from, int length)
: string_(string), from_(from), length_(length) { }
virtual uint32_t Hash() {
ASSERT(length_ >= 0);
ASSERT(from_ + length_ <= string_->length());
- uint8_t* chars = string_->GetChars() + from_;
+ const Char* chars = GetChars() + from_;
hash_field_ = StringHasher::HashSequentialString(
chars, length_, string_->GetHeap()->HashSeed());
uint32_t result = hash_field_ >> String::kHashShift;
@@ -517,20 +516,17 @@ class SubStringOneByteStringKey : public HashTableKey
{
return result;
}
-
virtual uint32_t HashForObject(Object* other) {
return String::cast(other)->Hash();
}
- virtual bool IsMatch(Object* string) {
- Vector<const uint8_t> chars(string_->GetChars() + from_, length_);
- return String::cast(string)->IsOneByteEqualTo(chars);
- }
-
+ virtual bool IsMatch(Object* string);
virtual MaybeObject* AsObject(Heap* heap);
private:
- Handle<SeqOneByteString> string_;
+ const Char* GetChars();
+
+ Handle<String> string_;
int from_;
int length_;
uint32_t hash_field_;
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
9c1a9cd69f5ee0ceba6416fdba0a2309660f541b..8256764158e47e88d6aa687ccb443cab0118a3ad
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -13990,19 +13990,63 @@ MaybeObject* OneByteStringKey::AsObject(Heap*
heap) {
}
-MaybeObject* SubStringOneByteStringKey::AsObject(Heap* heap) {
+MaybeObject* TwoByteStringKey::AsObject(Heap* heap) {
+ if (hash_field_ == 0) Hash();
+ return heap->AllocateTwoByteInternalizedString(string_, hash_field_);
+}
+
+
+template<>
+const uint8_t* SubStringKey<uint8_t>::GetChars() {
+ return string_->IsSeqOneByteString()
+ ? SeqOneByteString::cast(*string_)->GetChars()
+ : ExternalAsciiString::cast(*string_)->GetChars();
+}
+
+
+template<>
+const uint16_t* SubStringKey<uint16_t>::GetChars() {
+ return string_->IsSeqTwoByteString()
+ ? SeqTwoByteString::cast(*string_)->GetChars()
+ : ExternalTwoByteString::cast(*string_)->GetChars();
+}
+
+
+template<>
+MaybeObject* SubStringKey<uint8_t>::AsObject(Heap* heap) {
if (hash_field_ == 0) Hash();
- Vector<const uint8_t> chars(string_->GetChars() + from_, length_);
+ Vector<const uint8_t> chars(GetChars() + from_, length_);
return heap->AllocateOneByteInternalizedString(chars, hash_field_);
}
-MaybeObject* TwoByteStringKey::AsObject(Heap* heap) {
+template<>
+MaybeObject* SubStringKey<uint16_t>::AsObject(
+ Heap* heap) {
if (hash_field_ == 0) Hash();
- return heap->AllocateTwoByteInternalizedString(string_, hash_field_);
+ Vector<const uint16_t> chars(GetChars() + from_, length_);
+ return heap->AllocateTwoByteInternalizedString(chars, hash_field_);
+}
+
+
+template<>
+bool SubStringKey<uint8_t>::IsMatch(Object* string) {
+ Vector<const uint8_t> chars(GetChars() + from_, length_);
+ return String::cast(string)->IsOneByteEqualTo(chars);
}
+template<>
+bool SubStringKey<uint16_t>::IsMatch(Object* string) {
+ Vector<const uint16_t> chars(GetChars() + from_, length_);
+ return String::cast(string)->IsTwoByteEqualTo(chars);
+}
+
+
+template class SubStringKey<uint8_t>;
+template class SubStringKey<uint16_t>;
+
+
// InternalizedStringKey carries a string/internalized-string object as
key.
class InternalizedStringKey : public HashTableKey {
public:
--
--
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.