OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 4642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4653 decoder->Reset(str.start(), str.length()); | 4653 decoder->Reset(str.start(), str.length()); |
4654 int i; | 4654 int i; |
4655 for (i = 0; i < slen && decoder->has_more(); i++) { | 4655 for (i = 0; i < slen && decoder->has_more(); i++) { |
4656 uc32 r = decoder->GetNext(); | 4656 uc32 r = decoder->GetNext(); |
4657 if (Get(i) != r) return false; | 4657 if (Get(i) != r) return false; |
4658 } | 4658 } |
4659 return i == slen && !decoder->has_more(); | 4659 return i == slen && !decoder->has_more(); |
4660 } | 4660 } |
4661 | 4661 |
4662 | 4662 |
| 4663 template <typename schar> |
| 4664 static inline uint32_t HashSequentialString(const schar* chars, int length) { |
| 4665 StringHasher hasher(length); |
| 4666 if (!hasher.has_trivial_hash()) { |
| 4667 int i; |
| 4668 for (i = 0; hasher.is_array_index() && (i < length); i++) { |
| 4669 hasher.AddCharacter(chars[i]); |
| 4670 } |
| 4671 for (; i < length; i++) { |
| 4672 hasher.AddCharacterNoIndex(chars[i]); |
| 4673 } |
| 4674 } |
| 4675 return hasher.GetHashField(); |
| 4676 } |
| 4677 |
| 4678 |
4663 uint32_t String::ComputeAndSetHash() { | 4679 uint32_t String::ComputeAndSetHash() { |
4664 // Should only be called if hash code has not yet been computed. | 4680 // Should only be called if hash code has not yet been computed. |
4665 ASSERT(!(hash_field() & kHashComputedMask)); | 4681 ASSERT(!(hash_field() & kHashComputedMask)); |
4666 | 4682 |
| 4683 const int len = length(); |
| 4684 |
4667 // Compute the hash code. | 4685 // Compute the hash code. |
4668 StringInputBuffer buffer(this); | 4686 uint32_t field = 0; |
4669 uint32_t field = ComputeHashField(&buffer, length()); | 4687 if (StringShape(this).IsSequentialAscii()) { |
| 4688 field = HashSequentialString(SeqAsciiString::cast(this)->GetChars(), len); |
| 4689 } else if (StringShape(this).IsSequentialTwoByte()) { |
| 4690 field = HashSequentialString(SeqTwoByteString::cast(this)->GetChars(), len); |
| 4691 } else { |
| 4692 StringInputBuffer buffer(this); |
| 4693 field = ComputeHashField(&buffer, len); |
| 4694 } |
4670 | 4695 |
4671 // Store the hash code in the object. | 4696 // Store the hash code in the object. |
4672 set_hash_field(field); | 4697 set_hash_field(field); |
4673 | 4698 |
4674 // Check the hash code is there. | 4699 // Check the hash code is there. |
4675 ASSERT(hash_field() & kHashComputedMask); | 4700 ASSERT(hash_field() & kHashComputedMask); |
4676 uint32_t result = field >> kHashShift; | 4701 uint32_t result = field >> kHashShift; |
4677 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 4702 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
4678 return result; | 4703 return result; |
4679 } | 4704 } |
(...skipping 3833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8513 if (break_point_objects()->IsUndefined()) return 0; | 8538 if (break_point_objects()->IsUndefined()) return 0; |
8514 // Single beak point. | 8539 // Single beak point. |
8515 if (!break_point_objects()->IsFixedArray()) return 1; | 8540 if (!break_point_objects()->IsFixedArray()) return 1; |
8516 // Multiple break points. | 8541 // Multiple break points. |
8517 return FixedArray::cast(break_point_objects())->length(); | 8542 return FixedArray::cast(break_point_objects())->length(); |
8518 } | 8543 } |
8519 #endif | 8544 #endif |
8520 | 8545 |
8521 | 8546 |
8522 } } // namespace v8::internal | 8547 } } // namespace v8::internal |
OLD | NEW |