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

Side by Side Diff: src/objects.h

Issue 9600009: Fix input and output to handle UTF16 surrogate pairs. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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()); }
6768 static int Utf8Length(String* input, int from, int to);
6769
6770 // Return a 16 bit Unicode representation of the string. 6772 // Return a 16 bit Unicode representation of the string.
6771 // The string should be nearly flat, otherwise the performance of 6773 // The string should be nearly flat, otherwise the performance of
6772 // of this method may be very bad. Setting robustness_flag to 6774 // of this method may be very bad. Setting robustness_flag to
6773 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it 6775 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
6774 // handles unexpected data without causing assert failures and it does not 6776 // handles unexpected data without causing assert failures and it does not
6775 // do any heap allocations. This is useful when printing stack traces. 6777 // do any heap allocations. This is useful when printing stack traces.
6776 SmartArrayPointer<uc16> ToWideCString( 6778 SmartArrayPointer<uc16> ToWideCString(
6777 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); 6779 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL);
6778 6780
6779 // Tells whether the hash code has been computed. 6781 // Tells whether the hash code has been computed.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
6825 static const int kHashFieldOffset = kLengthOffset + kPointerSize; 6827 static const int kHashFieldOffset = kLengthOffset + kPointerSize;
6826 static const int kSize = kHashFieldOffset + kPointerSize; 6828 static const int kSize = kHashFieldOffset + kPointerSize;
6827 6829
6828 // Maximum number of characters to consider when trying to convert a string 6830 // Maximum number of characters to consider when trying to convert a string
6829 // value into an array index. 6831 // value into an array index.
6830 static const int kMaxArrayIndexSize = 10; 6832 static const int kMaxArrayIndexSize = 10;
6831 6833
6832 // Max ASCII char code. 6834 // Max ASCII char code.
6833 static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; 6835 static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar;
6834 static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; 6836 static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar;
6835 static const int kMaxUC16CharCode = 0xffff; 6837 static const int kMaxUtf16CodeUnit = 0xffff;
6836 6838
6837 // Mask constant for checking if a string has a computed hash code 6839 // 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 6840 // 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 6841 // 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 6842 // computed the 2nd bit tells whether the string can be used as an
6841 // array index. 6843 // array index.
6842 static const int kHashNotComputedMask = 1; 6844 static const int kHashNotComputedMask = 1;
6843 static const int kIsNotArrayIndexMask = 1 << 1; 6845 static const int kIsNotArrayIndexMask = 1 << 1;
6844 static const int kNofHashBitFields = 2; 6846 static const int kNofHashBitFields = 2;
6845 6847
(...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after
8461 } else { 8463 } else {
8462 value &= ~(1 << bit_position); 8464 value &= ~(1 << bit_position);
8463 } 8465 }
8464 return value; 8466 return value;
8465 } 8467 }
8466 }; 8468 };
8467 8469
8468 } } // namespace v8::internal 8470 } } // namespace v8::internal
8469 8471
8470 #endif // V8_OBJECTS_H_ 8472 #endif // V8_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698