OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 6491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6502 | 6502 |
6503 class StringHasher { | 6503 class StringHasher { |
6504 public: | 6504 public: |
6505 explicit inline StringHasher(int length, uint32_t seed); | 6505 explicit inline StringHasher(int length, uint32_t seed); |
6506 | 6506 |
6507 // Returns true if the hash of this string can be computed without | 6507 // Returns true if the hash of this string can be computed without |
6508 // looking at the contents. | 6508 // looking at the contents. |
6509 inline bool has_trivial_hash(); | 6509 inline bool has_trivial_hash(); |
6510 | 6510 |
6511 // Add a character to the hash and update the array index calculation. | 6511 // Add a character to the hash and update the array index calculation. |
6512 inline void AddCharacter(uc32 c); | 6512 inline void AddCharacter(uint32_t c); |
6513 | 6513 |
6514 // Adds a character to the hash but does not update the array index | 6514 // Adds a character to the hash but does not update the array index |
6515 // calculation. This can only be called when it has been verified | 6515 // calculation. This can only be called when it has been verified |
6516 // that the input is not an array index. | 6516 // that the input is not an array index. |
6517 inline void AddCharacterNoIndex(uc32 c); | 6517 inline void AddCharacterNoIndex(uint32_t c); |
6518 | |
6519 // Add a character above 0xffff as a surrogate pair. These can get into | |
6520 // the hasher through the routines that take a UTF-8 string and make a symbol. | |
6521 void AddSurrogatePair(uc32 c); | |
6522 void AddSurrogatePairNoIndex(uc32 c); | |
6518 | 6523 |
6519 // Returns the value to store in the hash field of a string with | 6524 // Returns the value to store in the hash field of a string with |
6520 // the given length and contents. | 6525 // the given length and contents. |
6521 uint32_t GetHashField(); | 6526 uint32_t GetHashField(); |
6522 | 6527 |
6523 // Returns true if the characters seen so far make up a legal array | 6528 // Returns true if the characters seen so far make up a legal array |
6524 // index. | 6529 // index. |
6525 bool is_array_index() { return is_array_index_; } | 6530 bool is_array_index() { return is_array_index_; } |
6526 | 6531 |
6527 bool is_valid() { return is_valid_; } | 6532 bool is_valid() { return is_valid_; } |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6757 SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls, | 6762 SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls, |
6758 RobustnessFlag robustness_flag, | 6763 RobustnessFlag robustness_flag, |
6759 int offset, | 6764 int offset, |
6760 int length, | 6765 int length, |
6761 int* length_output = 0); | 6766 int* length_output = 0); |
6762 SmartArrayPointer<char> ToCString( | 6767 SmartArrayPointer<char> ToCString( |
6763 AllowNullsFlag allow_nulls = DISALLOW_NULLS, | 6768 AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
6764 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, | 6769 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
6765 int* length_output = 0); | 6770 int* length_output = 0); |
6766 | 6771 |
6767 inline int Utf8Length() { return Utf8Length(this, 0, length()); } | 6772 inline int Utf8Length() { |
rossberg
2012/03/07 13:32:47
Even with the inline definition here, I think a co
Erik Corry
2012/03/11 19:29:22
This issue disappears with the move to a handle ba
| |
6768 static int Utf8Length(String* input, int from, int to); | 6773 bool dummy; |
6774 bool failure = false; | |
6775 int len = Utf8Length(this, 0, length(), false, 100, &failure, &dummy); | |
6776 if (failure) return -1; | |
6777 return len; | |
6778 } | |
6779 // Call again on a flatter string if the failure variable gets set. | |
6780 static int Utf8Length(String* input, | |
rossberg
2012/03/07 13:32:47
Please specify the result of these functions in th
Erik Corry
2012/03/11 19:29:22
Done. (They are coded as 'illegal' UTF-8 sequence
| |
6781 int from, | |
6782 int to, | |
6783 bool preceeded_by_surrogate, | |
6784 int max_recursion, | |
rossberg
2012/03/07 13:32:47
Is this a useful interface? How is a caller suppos
Erik Corry
2012/03/11 19:29:22
Yes, this is the correct solution. This means it
| |
6785 bool* failure, | |
6786 bool* ends_in_surrogate); | |
6769 | 6787 |
6770 // Return a 16 bit Unicode representation of the string. | 6788 // Return a 16 bit Unicode representation of the string. |
6771 // The string should be nearly flat, otherwise the performance of | 6789 // The string should be nearly flat, otherwise the performance of |
6772 // of this method may be very bad. Setting robustness_flag to | 6790 // of this method may be very bad. Setting robustness_flag to |
6773 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it | 6791 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
6774 // handles unexpected data without causing assert failures and it does not | 6792 // handles unexpected data without causing assert failures and it does not |
6775 // do any heap allocations. This is useful when printing stack traces. | 6793 // do any heap allocations. This is useful when printing stack traces. |
6776 SmartArrayPointer<uc16> ToWideCString( | 6794 SmartArrayPointer<uc16> ToWideCString( |
6777 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); | 6795 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
6778 | 6796 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6825 static const int kHashFieldOffset = kLengthOffset + kPointerSize; | 6843 static const int kHashFieldOffset = kLengthOffset + kPointerSize; |
6826 static const int kSize = kHashFieldOffset + kPointerSize; | 6844 static const int kSize = kHashFieldOffset + kPointerSize; |
6827 | 6845 |
6828 // Maximum number of characters to consider when trying to convert a string | 6846 // Maximum number of characters to consider when trying to convert a string |
6829 // value into an array index. | 6847 // value into an array index. |
6830 static const int kMaxArrayIndexSize = 10; | 6848 static const int kMaxArrayIndexSize = 10; |
6831 | 6849 |
6832 // Max ASCII char code. | 6850 // Max ASCII char code. |
6833 static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; | 6851 static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; |
6834 static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; | 6852 static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; |
6835 static const int kMaxUC16CharCode = 0xffff; | 6853 static const int kMaxUtf16CodeUnit = 0xffff; |
6836 | 6854 |
6837 // Mask constant for checking if a string has a computed hash code | 6855 // Mask constant for checking if a string has a computed hash code |
6838 // and if it is an array index. The least significant bit indicates | 6856 // and if it is an array index. The least significant bit indicates |
6839 // whether a hash code has been computed. If the hash code has been | 6857 // whether a hash code has been computed. If the hash code has been |
6840 // computed the 2nd bit tells whether the string can be used as an | 6858 // computed the 2nd bit tells whether the string can be used as an |
6841 // array index. | 6859 // array index. |
6842 static const int kHashNotComputedMask = 1; | 6860 static const int kHashNotComputedMask = 1; |
6843 static const int kIsNotArrayIndexMask = 1 << 1; | 6861 static const int kIsNotArrayIndexMask = 1 << 1; |
6844 static const int kNofHashBitFields = 2; | 6862 static const int kNofHashBitFields = 2; |
6845 | 6863 |
(...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8461 } else { | 8479 } else { |
8462 value &= ~(1 << bit_position); | 8480 value &= ~(1 << bit_position); |
8463 } | 8481 } |
8464 return value; | 8482 return value; |
8465 } | 8483 } |
8466 }; | 8484 }; |
8467 | 8485 |
8468 } } // namespace v8::internal | 8486 } } // namespace v8::internal |
8469 | 8487 |
8470 #endif // V8_OBJECTS_H_ | 8488 #endif // V8_OBJECTS_H_ |
OLD | NEW |