OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 9314 matching lines...) Loading... |
9325 if (content.IsTwoByte()) { | 9325 if (content.IsTwoByte()) { |
9326 return CompareChars(content.ToUC16Vector().start(), str.start(), slen) == 0; | 9326 return CompareChars(content.ToUC16Vector().start(), str.start(), slen) == 0; |
9327 } | 9327 } |
9328 for (int i = 0; i < slen; i++) { | 9328 for (int i = 0; i < slen; i++) { |
9329 if (Get(i) != str[i]) return false; | 9329 if (Get(i) != str[i]) return false; |
9330 } | 9330 } |
9331 return true; | 9331 return true; |
9332 } | 9332 } |
9333 | 9333 |
9334 | 9334 |
9335 class IteratingStringHasher: public StringHasher { | |
9336 public: | |
9337 static inline uint32_t Hash(String* string, uint32_t seed) { | |
9338 IteratingStringHasher hasher(string->length(), seed); | |
9339 // Nothing to do. | |
9340 if (hasher.has_trivial_hash()) return hasher.GetHashField(); | |
9341 ConsString* cons_string = String::VisitFlat(&hasher, string); | |
9342 // The string was flat. | |
9343 if (cons_string == NULL) return hasher.GetHashField(); | |
9344 // This is a ConsString, iterate across it. | |
9345 ConsStringIteratorOp op(cons_string); | |
9346 int offset; | |
9347 while (NULL != (string = op.Next(&offset))) { | |
9348 String::VisitFlat(&hasher, string, offset); | |
9349 } | |
9350 return hasher.GetHashField(); | |
9351 } | |
9352 inline void VisitOneByteString(const uint8_t* chars, int length) { | |
9353 AddCharacters(chars, length); | |
9354 } | |
9355 inline void VisitTwoByteString(const uint16_t* chars, int length) { | |
9356 AddCharacters(chars, length); | |
9357 } | |
9358 | |
9359 private: | |
9360 inline IteratingStringHasher(int len, uint32_t seed) | |
9361 : StringHasher(len, seed) { | |
9362 } | |
9363 DISALLOW_COPY_AND_ASSIGN(IteratingStringHasher); | |
9364 }; | |
9365 | |
9366 | |
9367 uint32_t String::ComputeAndSetHash() { | 9335 uint32_t String::ComputeAndSetHash() { |
9368 // Should only be called if hash code has not yet been computed. | 9336 // Should only be called if hash code has not yet been computed. |
9369 ASSERT(!HasHashCode()); | 9337 ASSERT(!HasHashCode()); |
9370 | 9338 |
9371 // Store the hash code in the object. | 9339 // Store the hash code in the object. |
9372 uint32_t field = IteratingStringHasher::Hash(this, GetHeap()->HashSeed()); | 9340 uint32_t field = IteratingStringHasher::Hash(this, GetHeap()->HashSeed()); |
9373 set_hash_field(field); | 9341 set_hash_field(field); |
9374 | 9342 |
9375 // Check the hash code is there. | 9343 // Check the hash code is there. |
9376 ASSERT(HasHashCode()); | 9344 ASSERT(HasHashCode()); |
(...skipping 7570 matching lines...) Loading... |
16947 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16915 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16948 static const char* error_messages_[] = { | 16916 static const char* error_messages_[] = { |
16949 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16917 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16950 }; | 16918 }; |
16951 #undef ERROR_MESSAGES_TEXTS | 16919 #undef ERROR_MESSAGES_TEXTS |
16952 return error_messages_[reason]; | 16920 return error_messages_[reason]; |
16953 } | 16921 } |
16954 | 16922 |
16955 | 16923 |
16956 } } // namespace v8::internal | 16924 } } // namespace v8::internal |
OLD | NEW |