| OLD | NEW | 
|     1 // Copyright 2012 the V8 project authors. All rights reserved. |     1 // Copyright 2012 the V8 project authors. All rights reserved. | 
|     2 // Use of this source code is governed by a BSD-style license that can be |     2 // Use of this source code is governed by a BSD-style license that can be | 
|     3 // found in the LICENSE file. |     3 // found in the LICENSE file. | 
|     4 // |     4 // | 
|     5 // Review notes: |     5 // Review notes: | 
|     6 // |     6 // | 
|     7 // - The use of macros in these inline functions may seem superfluous |     7 // - The use of macros in these inline functions may seem superfluous | 
|     8 // but it is absolutely needed to make sure gcc generates optimal |     8 // but it is absolutely needed to make sure gcc generates optimal | 
|     9 // code. gcc is not happy when attempting to inline too deep. |     9 // code. gcc is not happy when attempting to inline too deep. | 
|    10 // |    10 // | 
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   492                                                  HashTableKey* key) { |   492                                                  HashTableKey* key) { | 
|   493   return key->AsHandle(isolate); |   493   return key->AsHandle(isolate); | 
|   494 } |   494 } | 
|   495  |   495  | 
|   496 template <typename Char> |   496 template <typename Char> | 
|   497 class SequentialStringKey : public HashTableKey { |   497 class SequentialStringKey : public HashTableKey { | 
|   498  public: |   498  public: | 
|   499   explicit SequentialStringKey(Vector<const Char> string, uint32_t seed) |   499   explicit SequentialStringKey(Vector<const Char> string, uint32_t seed) | 
|   500       : string_(string), hash_field_(0), seed_(seed) { } |   500       : string_(string), hash_field_(0), seed_(seed) { } | 
|   501  |   501  | 
|   502   virtual uint32_t Hash() V8_OVERRIDE { |   502   virtual uint32_t Hash() OVERRIDE { | 
|   503     hash_field_ = StringHasher::HashSequentialString<Char>(string_.start(), |   503     hash_field_ = StringHasher::HashSequentialString<Char>(string_.start(), | 
|   504                                                            string_.length(), |   504                                                            string_.length(), | 
|   505                                                            seed_); |   505                                                            seed_); | 
|   506  |   506  | 
|   507     uint32_t result = hash_field_ >> String::kHashShift; |   507     uint32_t result = hash_field_ >> String::kHashShift; | 
|   508     DCHECK(result != 0);  // Ensure that the hash value of 0 is never computed. |   508     DCHECK(result != 0);  // Ensure that the hash value of 0 is never computed. | 
|   509     return result; |   509     return result; | 
|   510   } |   510   } | 
|   511  |   511  | 
|   512  |   512  | 
|   513   virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { |   513   virtual uint32_t HashForObject(Object* other) OVERRIDE { | 
|   514     return String::cast(other)->Hash(); |   514     return String::cast(other)->Hash(); | 
|   515   } |   515   } | 
|   516  |   516  | 
|   517   Vector<const Char> string_; |   517   Vector<const Char> string_; | 
|   518   uint32_t hash_field_; |   518   uint32_t hash_field_; | 
|   519   uint32_t seed_; |   519   uint32_t seed_; | 
|   520 }; |   520 }; | 
|   521  |   521  | 
|   522  |   522  | 
|   523 class OneByteStringKey : public SequentialStringKey<uint8_t> { |   523 class OneByteStringKey : public SequentialStringKey<uint8_t> { | 
|   524  public: |   524  public: | 
|   525   OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) |   525   OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) | 
|   526       : SequentialStringKey<uint8_t>(str, seed) { } |   526       : SequentialStringKey<uint8_t>(str, seed) { } | 
|   527  |   527  | 
|   528   virtual bool IsMatch(Object* string) V8_OVERRIDE { |   528   virtual bool IsMatch(Object* string) OVERRIDE { | 
|   529     return String::cast(string)->IsOneByteEqualTo(string_); |   529     return String::cast(string)->IsOneByteEqualTo(string_); | 
|   530   } |   530   } | 
|   531  |   531  | 
|   532   virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE; |   532   virtual Handle<Object> AsHandle(Isolate* isolate) OVERRIDE; | 
|   533 }; |   533 }; | 
|   534  |   534  | 
|   535  |   535  | 
|   536 class SeqOneByteSubStringKey : public HashTableKey { |   536 class SeqOneByteSubStringKey : public HashTableKey { | 
|   537  public: |   537  public: | 
|   538   SeqOneByteSubStringKey(Handle<SeqOneByteString> string, int from, int length) |   538   SeqOneByteSubStringKey(Handle<SeqOneByteString> string, int from, int length) | 
|   539       : string_(string), from_(from), length_(length) { |   539       : string_(string), from_(from), length_(length) { | 
|   540     DCHECK(string_->IsSeqOneByteString()); |   540     DCHECK(string_->IsSeqOneByteString()); | 
|   541   } |   541   } | 
|   542  |   542  | 
|   543   virtual uint32_t Hash() V8_OVERRIDE { |   543   virtual uint32_t Hash() OVERRIDE { | 
|   544     DCHECK(length_ >= 0); |   544     DCHECK(length_ >= 0); | 
|   545     DCHECK(from_ + length_ <= string_->length()); |   545     DCHECK(from_ + length_ <= string_->length()); | 
|   546     const uint8_t* chars = string_->GetChars() + from_; |   546     const uint8_t* chars = string_->GetChars() + from_; | 
|   547     hash_field_ = StringHasher::HashSequentialString( |   547     hash_field_ = StringHasher::HashSequentialString( | 
|   548         chars, length_, string_->GetHeap()->HashSeed()); |   548         chars, length_, string_->GetHeap()->HashSeed()); | 
|   549     uint32_t result = hash_field_ >> String::kHashShift; |   549     uint32_t result = hash_field_ >> String::kHashShift; | 
|   550     DCHECK(result != 0);  // Ensure that the hash value of 0 is never computed. |   550     DCHECK(result != 0);  // Ensure that the hash value of 0 is never computed. | 
|   551     return result; |   551     return result; | 
|   552   } |   552   } | 
|   553  |   553  | 
|   554   virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { |   554   virtual uint32_t HashForObject(Object* other) OVERRIDE { | 
|   555     return String::cast(other)->Hash(); |   555     return String::cast(other)->Hash(); | 
|   556   } |   556   } | 
|   557  |   557  | 
|   558   virtual bool IsMatch(Object* string) V8_OVERRIDE; |   558   virtual bool IsMatch(Object* string) OVERRIDE; | 
|   559   virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE; |   559   virtual Handle<Object> AsHandle(Isolate* isolate) OVERRIDE; | 
|   560  |   560  | 
|   561  private: |   561  private: | 
|   562   Handle<SeqOneByteString> string_; |   562   Handle<SeqOneByteString> string_; | 
|   563   int from_; |   563   int from_; | 
|   564   int length_; |   564   int length_; | 
|   565   uint32_t hash_field_; |   565   uint32_t hash_field_; | 
|   566 }; |   566 }; | 
|   567  |   567  | 
|   568  |   568  | 
|   569 class TwoByteStringKey : public SequentialStringKey<uc16> { |   569 class TwoByteStringKey : public SequentialStringKey<uc16> { | 
|   570  public: |   570  public: | 
|   571   explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) |   571   explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) | 
|   572       : SequentialStringKey<uc16>(str, seed) { } |   572       : SequentialStringKey<uc16>(str, seed) { } | 
|   573  |   573  | 
|   574   virtual bool IsMatch(Object* string) V8_OVERRIDE { |   574   virtual bool IsMatch(Object* string) OVERRIDE { | 
|   575     return String::cast(string)->IsTwoByteEqualTo(string_); |   575     return String::cast(string)->IsTwoByteEqualTo(string_); | 
|   576   } |   576   } | 
|   577  |   577  | 
|   578   virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE; |   578   virtual Handle<Object> AsHandle(Isolate* isolate) OVERRIDE; | 
|   579 }; |   579 }; | 
|   580  |   580  | 
|   581  |   581  | 
|   582 // Utf8StringKey carries a vector of chars as key. |   582 // Utf8StringKey carries a vector of chars as key. | 
|   583 class Utf8StringKey : public HashTableKey { |   583 class Utf8StringKey : public HashTableKey { | 
|   584  public: |   584  public: | 
|   585   explicit Utf8StringKey(Vector<const char> string, uint32_t seed) |   585   explicit Utf8StringKey(Vector<const char> string, uint32_t seed) | 
|   586       : string_(string), hash_field_(0), seed_(seed) { } |   586       : string_(string), hash_field_(0), seed_(seed) { } | 
|   587  |   587  | 
|   588   virtual bool IsMatch(Object* string) V8_OVERRIDE { |   588   virtual bool IsMatch(Object* string) OVERRIDE { | 
|   589     return String::cast(string)->IsUtf8EqualTo(string_); |   589     return String::cast(string)->IsUtf8EqualTo(string_); | 
|   590   } |   590   } | 
|   591  |   591  | 
|   592   virtual uint32_t Hash() V8_OVERRIDE { |   592   virtual uint32_t Hash() OVERRIDE { | 
|   593     if (hash_field_ != 0) return hash_field_ >> String::kHashShift; |   593     if (hash_field_ != 0) return hash_field_ >> String::kHashShift; | 
|   594     hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); |   594     hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); | 
|   595     uint32_t result = hash_field_ >> String::kHashShift; |   595     uint32_t result = hash_field_ >> String::kHashShift; | 
|   596     DCHECK(result != 0);  // Ensure that the hash value of 0 is never computed. |   596     DCHECK(result != 0);  // Ensure that the hash value of 0 is never computed. | 
|   597     return result; |   597     return result; | 
|   598   } |   598   } | 
|   599  |   599  | 
|   600   virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { |   600   virtual uint32_t HashForObject(Object* other) OVERRIDE { | 
|   601     return String::cast(other)->Hash(); |   601     return String::cast(other)->Hash(); | 
|   602   } |   602   } | 
|   603  |   603  | 
|   604   virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE { |   604   virtual Handle<Object> AsHandle(Isolate* isolate) OVERRIDE { | 
|   605     if (hash_field_ == 0) Hash(); |   605     if (hash_field_ == 0) Hash(); | 
|   606     return isolate->factory()->NewInternalizedStringFromUtf8( |   606     return isolate->factory()->NewInternalizedStringFromUtf8( | 
|   607         string_, chars_, hash_field_); |   607         string_, chars_, hash_field_); | 
|   608   } |   608   } | 
|   609  |   609  | 
|   610   Vector<const char> string_; |   610   Vector<const char> string_; | 
|   611   uint32_t hash_field_; |   611   uint32_t hash_field_; | 
|   612   int chars_;  // Caches the number of characters when computing the hash code. |   612   int chars_;  // Caches the number of characters when computing the hash code. | 
|   613   uint32_t seed_; |   613   uint32_t seed_; | 
|   614 }; |   614 }; | 
| (...skipping 6633 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  7248 #undef READ_SHORT_FIELD |  7248 #undef READ_SHORT_FIELD | 
|  7249 #undef WRITE_SHORT_FIELD |  7249 #undef WRITE_SHORT_FIELD | 
|  7250 #undef READ_BYTE_FIELD |  7250 #undef READ_BYTE_FIELD | 
|  7251 #undef WRITE_BYTE_FIELD |  7251 #undef WRITE_BYTE_FIELD | 
|  7252 #undef NOBARRIER_READ_BYTE_FIELD |  7252 #undef NOBARRIER_READ_BYTE_FIELD | 
|  7253 #undef NOBARRIER_WRITE_BYTE_FIELD |  7253 #undef NOBARRIER_WRITE_BYTE_FIELD | 
|  7254  |  7254  | 
|  7255 } }  // namespace v8::internal |  7255 } }  // namespace v8::internal | 
|  7256  |  7256  | 
|  7257 #endif  // V8_OBJECTS_INL_H_ |  7257 #endif  // V8_OBJECTS_INL_H_ | 
| OLD | NEW |