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

Unified Diff: src/objects-inl.h

Issue 143223004: Generalize internalization of substrings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add handling of sliced substrings Created 6 years, 11 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
« no previous file with comments | « src/objects.cc ('k') | no next file » | 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 fb996a219e28df171504916345c496394ab4c3c1..961041c05dd22d13be79a10564fd8f17bae0005f 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -499,17 +499,21 @@ 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)
- : string_(string), from_(from), length_(length) { }
+ SubStringKey(Handle<String> string, int from, int 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);
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 +521,25 @@ 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();
+ 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_;
int length_;
uint32_t hash_field_;
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698