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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 kIsSymbolMask | | 525 kIsSymbolMask | |
526 kStringRepresentationMask; | 526 kStringRepresentationMask; |
527 const uint32_t kShortcutTypeTag = kConsStringTag; | 527 const uint32_t kShortcutTypeTag = kConsStringTag; |
528 | 528 |
529 | 529 |
530 enum InstanceType { | 530 enum InstanceType { |
531 // String types. | 531 // String types. |
532 SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, | 532 SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, |
533 ASCII_SYMBOL_TYPE = kOneByteStringTag | kAsciiDataHintTag | kSymbolTag | | 533 ASCII_SYMBOL_TYPE = kOneByteStringTag | kAsciiDataHintTag | kSymbolTag | |
534 kSeqStringTag, | 534 kSeqStringTag, |
535 ONE_BYTE_SYMBOL_TYPE = kOneByteStringTag | kSymbolTag | kSeqStringTag, | |
535 CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, | 536 CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, |
536 CONS_ASCII_SYMBOL_TYPE = kOneByteStringTag | kAsciiDataHintTag | kSymbolTag | | 537 CONS_ASCII_SYMBOL_TYPE = kOneByteStringTag | kAsciiDataHintTag | kSymbolTag | |
537 kConsStringTag, | 538 kConsStringTag, |
539 CONS_ONE_BYTE_SYMBOL_TYPE = kOneByteStringTag | kSymbolTag | kConsStringTag, | |
538 SHORT_EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | | 540 SHORT_EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | |
539 kExternalStringTag | kShortExternalStringTag, | 541 kExternalStringTag | kShortExternalStringTag, |
540 SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = | 542 SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
541 kTwoByteStringTag | kSymbolTag | kExternalStringTag | | 543 kTwoByteStringTag | kSymbolTag | kExternalStringTag | |
542 kAsciiDataHintTag | kShortExternalStringTag, | 544 kAsciiDataHintTag | kShortExternalStringTag, |
543 SHORT_EXTERNAL_ASCII_SYMBOL_TYPE = kOneByteStringTag | kAsciiDataHintTag | | 545 SHORT_EXTERNAL_ASCII_SYMBOL_TYPE = kOneByteStringTag | kAsciiDataHintTag | |
544 kExternalStringTag | kSymbolTag | | 546 kExternalStringTag | kSymbolTag | |
545 kShortExternalStringTag, | 547 kShortExternalStringTag, |
548 SHORT_EXTERNAL_ONE_BYTE_SYMBOL_TYPE = kOneByteStringTag | | |
549 kExternalStringTag | kSymbolTag | | |
550 kShortExternalStringTag, | |
546 EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, | 551 EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, |
547 EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = | 552 EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
548 kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, | 553 kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, |
549 EXTERNAL_ASCII_SYMBOL_TYPE = | 554 EXTERNAL_ASCII_SYMBOL_TYPE = |
550 kOneByteStringTag | kAsciiDataHintTag | kSymbolTag | kExternalStringTag, | 555 kOneByteStringTag | kAsciiDataHintTag | kSymbolTag | kExternalStringTag, |
556 EXTERNAL_ONE_BYTE_SYMBOL_TYPE = | |
557 kOneByteStringTag | kSymbolTag | kExternalStringTag, | |
551 STRING_TYPE = kTwoByteStringTag | kSeqStringTag, | 558 STRING_TYPE = kTwoByteStringTag | kSeqStringTag, |
552 ASCII_STRING_TYPE = kOneByteStringTag | kAsciiDataHintTag | kSeqStringTag, | 559 ASCII_STRING_TYPE = kOneByteStringTag | kAsciiDataHintTag | kSeqStringTag, |
560 ONE_BYTE_STRING_TYPE = kOneByteStringTag | kSeqStringTag, | |
553 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, | 561 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, |
554 CONS_ASCII_STRING_TYPE = | 562 CONS_ASCII_STRING_TYPE = |
555 kOneByteStringTag | kAsciiDataHintTag | kConsStringTag, | 563 kOneByteStringTag | kAsciiDataHintTag | kConsStringTag, |
564 CONS_ONE_BYTE_STRING_TYPE = kOneByteStringTag | kConsStringTag, | |
556 SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag, | 565 SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag, |
557 SLICED_ASCII_STRING_TYPE = | 566 SLICED_ASCII_STRING_TYPE = |
558 kOneByteStringTag | kAsciiDataHintTag | kSlicedStringTag, | 567 kOneByteStringTag | kAsciiDataHintTag | kSlicedStringTag, |
568 SLICED_ONE_BYTE_STRING_TYPE = kOneByteStringTag | kSlicedStringTag, | |
559 SHORT_EXTERNAL_STRING_TYPE = | 569 SHORT_EXTERNAL_STRING_TYPE = |
560 kTwoByteStringTag | kExternalStringTag | kShortExternalStringTag, | 570 kTwoByteStringTag | kExternalStringTag | kShortExternalStringTag, |
561 SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = | 571 SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
562 kTwoByteStringTag | kExternalStringTag | | 572 kTwoByteStringTag | kExternalStringTag | |
563 kAsciiDataHintTag | kShortExternalStringTag, | 573 kAsciiDataHintTag | kShortExternalStringTag, |
564 SHORT_EXTERNAL_ASCII_STRING_TYPE = | 574 SHORT_EXTERNAL_ASCII_STRING_TYPE = |
565 kOneByteStringTag | kAsciiDataHintTag | | 575 kOneByteStringTag | kAsciiDataHintTag | |
566 kExternalStringTag | kShortExternalStringTag, | 576 kExternalStringTag | kShortExternalStringTag, |
577 SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE = | |
578 kOneByteStringTag | kExternalStringTag | kShortExternalStringTag, | |
567 EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, | 579 EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, |
568 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = | 580 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
569 kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, | 581 kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, |
570 // LAST_STRING_TYPE | |
571 EXTERNAL_ASCII_STRING_TYPE = | 582 EXTERNAL_ASCII_STRING_TYPE = |
572 kOneByteStringTag | kAsciiDataHintTag | kExternalStringTag, | 583 kOneByteStringTag | kAsciiDataHintTag | kExternalStringTag, |
584 // LAST_STRING_TYPE | |
585 EXTERNAL_ONE_BYTE_STRING_TYPE = kOneByteStringTag | kExternalStringTag, | |
573 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, | 586 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, |
574 | 587 |
575 // Objects allocated in their own spaces (never in new space). | 588 // Objects allocated in their own spaces (never in new space). |
576 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE | 589 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE |
577 CODE_TYPE, | 590 CODE_TYPE, |
578 ODDBALL_TYPE, | 591 ODDBALL_TYPE, |
579 JS_GLOBAL_PROPERTY_CELL_TYPE, | 592 JS_GLOBAL_PROPERTY_CELL_TYPE, |
580 | 593 |
581 // "Data", objects that cannot contain non-map-word pointers to heap | 594 // "Data", objects that cannot contain non-map-word pointers to heap |
582 // objects. | 595 // objects. |
(...skipping 2438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3021 // No special elements in the prefix and the element size is 1 | 3034 // No special elements in the prefix and the element size is 1 |
3022 // because only the symbol itself (the key) needs to be stored. | 3035 // because only the symbol itself (the key) needs to be stored. |
3023 class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> { | 3036 class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> { |
3024 public: | 3037 public: |
3025 // Find symbol in the symbol table. If it is not there yet, it is | 3038 // Find symbol in the symbol table. If it is not there yet, it is |
3026 // added. The return value is the symbol table which might have | 3039 // added. The return value is the symbol table which might have |
3027 // been enlarged. If the return value is not a failure, the symbol | 3040 // been enlarged. If the return value is not a failure, the symbol |
3028 // pointer *s is set to the symbol found. | 3041 // pointer *s is set to the symbol found. |
3029 MUST_USE_RESULT MaybeObject* LookupUtf8Symbol(Vector<const char> str, | 3042 MUST_USE_RESULT MaybeObject* LookupUtf8Symbol(Vector<const char> str, |
3030 Object** s); | 3043 Object** s); |
3031 MUST_USE_RESULT MaybeObject* LookupOneByteSymbol(Vector<const char> str, | 3044 MUST_USE_RESULT MaybeObject* LookupOneByteSymbol(Vector<const uint8_t> str, |
3032 Object** s); | 3045 Object** s); |
3033 MUST_USE_RESULT MaybeObject* LookupSubStringOneByteSymbol( | 3046 MUST_USE_RESULT MaybeObject* LookupSubStringOneByteSymbol( |
3034 Handle<SeqOneByteString> str, | 3047 Handle<SeqOneByteString> str, |
3035 int from, | 3048 int from, |
3036 int length, | 3049 int length, |
3037 Object** s); | 3050 Object** s); |
3038 MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str, | 3051 MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str, |
3039 Object** s); | 3052 Object** s); |
3040 MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); | 3053 MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); |
3041 | 3054 |
(...skipping 4004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7046 // Representation of the flat content of a String. | 7059 // Representation of the flat content of a String. |
7047 // A non-flat string doesn't have flat content. | 7060 // A non-flat string doesn't have flat content. |
7048 // A flat string has content that's encoded as a sequence of either | 7061 // A flat string has content that's encoded as a sequence of either |
7049 // ASCII chars or two-byte UC16. | 7062 // ASCII chars or two-byte UC16. |
7050 // Returned by String::GetFlatContent(). | 7063 // Returned by String::GetFlatContent(). |
7051 class FlatContent { | 7064 class FlatContent { |
7052 public: | 7065 public: |
7053 // Returns true if the string is flat and this structure contains content. | 7066 // Returns true if the string is flat and this structure contains content. |
7054 bool IsFlat() { return state_ != NON_FLAT; } | 7067 bool IsFlat() { return state_ != NON_FLAT; } |
7055 // Returns true if the structure contains ASCII content. | 7068 // Returns true if the structure contains ASCII content. |
7056 bool IsAscii() { return state_ == ASCII; } | 7069 bool IsAscii() { return state_ == ASCII; } |
Yang
2013/01/07 16:15:07
I assume this is planned to be renamed to IsOneByt
| |
7057 // Returns true if the structure contains two-byte content. | 7070 // Returns true if the structure contains two-byte content. |
7058 bool IsTwoByte() { return state_ == TWO_BYTE; } | 7071 bool IsTwoByte() { return state_ == TWO_BYTE; } |
7059 | 7072 |
7073 // TODO(dcarney): Remove this function. | |
7060 // Return the ASCII content of the string. Only use if IsAscii() returns | 7074 // Return the ASCII content of the string. Only use if IsAscii() returns |
7061 // true. | 7075 // true. |
7062 Vector<const char> ToAsciiVector() { | 7076 Vector<const char> ToAsciiVector() { |
7063 ASSERT_EQ(ASCII, state_); | 7077 ASSERT_EQ(ASCII, state_); |
7064 return Vector<const char>::cast(buffer_); | 7078 return Vector<const char>::cast(buffer_); |
7065 } | 7079 } |
7080 // Return the one byte content of the string. Only use if IsAscii() returns | |
7081 // true. | |
7082 Vector<const uint8_t> ToOneByteVector() { | |
7083 ASSERT_EQ(ASCII, state_); | |
7084 return buffer_; | |
7085 } | |
7066 // Return the two-byte content of the string. Only use if IsTwoByte() | 7086 // Return the two-byte content of the string. Only use if IsTwoByte() |
7067 // returns true. | 7087 // returns true. |
7068 Vector<const uc16> ToUC16Vector() { | 7088 Vector<const uc16> ToUC16Vector() { |
7069 ASSERT_EQ(TWO_BYTE, state_); | 7089 ASSERT_EQ(TWO_BYTE, state_); |
7070 return Vector<const uc16>::cast(buffer_); | 7090 return Vector<const uc16>::cast(buffer_); |
7071 } | 7091 } |
7072 | 7092 |
7073 private: | 7093 private: |
7074 enum State { NON_FLAT, ASCII, TWO_BYTE }; | 7094 enum State { NON_FLAT, ASCII, TWO_BYTE }; |
7075 | 7095 |
(...skipping 30 matching lines...) Expand all Loading... | |
7106 // Cons and slices have an encoding flag that may not represent the actual | 7126 // Cons and slices have an encoding flag that may not represent the actual |
7107 // encoding of the underlying string. This is taken into account here. | 7127 // encoding of the underlying string. This is taken into account here. |
7108 // Requires: this->IsFlat() | 7128 // Requires: this->IsFlat() |
7109 inline bool IsOneByteRepresentationUnderneath(); | 7129 inline bool IsOneByteRepresentationUnderneath(); |
7110 inline bool IsTwoByteRepresentationUnderneath(); | 7130 inline bool IsTwoByteRepresentationUnderneath(); |
7111 | 7131 |
7112 // NOTE: this should be considered only a hint. False negatives are | 7132 // NOTE: this should be considered only a hint. False negatives are |
7113 // possible. | 7133 // possible. |
7114 inline bool HasOnlyAsciiChars(); | 7134 inline bool HasOnlyAsciiChars(); |
7115 | 7135 |
7136 inline bool IsOneByteConvertible(); | |
7137 | |
7116 // Get and set individual two byte chars in the string. | 7138 // Get and set individual two byte chars in the string. |
7117 inline void Set(int index, uint16_t value); | 7139 inline void Set(int index, uint16_t value); |
7118 // Get individual two byte char in the string. Repeated calls | 7140 // Get individual two byte char in the string. Repeated calls |
7119 // to this method are not efficient unless the string is flat. | 7141 // to this method are not efficient unless the string is flat. |
7120 INLINE(uint16_t Get(int index)); | 7142 INLINE(uint16_t Get(int index)); |
7121 | 7143 |
7122 // Try to flatten the string. Checks first inline to see if it is | 7144 // Try to flatten the string. Checks first inline to see if it is |
7123 // necessary. Does nothing if the string is not a cons string. | 7145 // necessary. Does nothing if the string is not a cons string. |
7124 // Flattening allocates a sequential string with the same data as | 7146 // Flattening allocates a sequential string with the same data as |
7125 // the given string and mutates the cons string to a degenerate | 7147 // the given string and mutates the cons string to a degenerate |
(...skipping 30 matching lines...) Expand all Loading... | |
7156 // ASCII and two byte string types. | 7178 // ASCII and two byte string types. |
7157 bool MarkAsUndetectable(); | 7179 bool MarkAsUndetectable(); |
7158 | 7180 |
7159 // Return a substring. | 7181 // Return a substring. |
7160 MUST_USE_RESULT MaybeObject* SubString(int from, | 7182 MUST_USE_RESULT MaybeObject* SubString(int from, |
7161 int to, | 7183 int to, |
7162 PretenureFlag pretenure = NOT_TENURED); | 7184 PretenureFlag pretenure = NOT_TENURED); |
7163 | 7185 |
7164 // String equality operations. | 7186 // String equality operations. |
7165 inline bool Equals(String* other); | 7187 inline bool Equals(String* other); |
7166 bool IsEqualTo(Vector<const char> str); | 7188 bool IsUtf8EqualTo(Vector<const char> str); |
7167 bool IsAsciiEqualTo(Vector<const char> str); | 7189 bool IsOneByteEqualTo(Vector<const uint8_t> str); |
7168 bool IsTwoByteEqualTo(Vector<const uc16> str); | 7190 bool IsTwoByteEqualTo(Vector<const uc16> str); |
7169 | 7191 |
7170 // Return a UTF8 representation of the string. The string is null | 7192 // Return a UTF8 representation of the string. The string is null |
7171 // terminated but may optionally contain nulls. Length is returned | 7193 // terminated but may optionally contain nulls. Length is returned |
7172 // in length_output if length_output is not a null pointer The string | 7194 // in length_output if length_output is not a null pointer The string |
7173 // should be nearly flat, otherwise the performance of this method may | 7195 // should be nearly flat, otherwise the performance of this method may |
7174 // be very slow (quadratic in the length). Setting robustness_flag to | 7196 // be very slow (quadratic in the length). Setting robustness_flag to |
7175 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it | 7197 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
7176 // handles unexpected data without causing assert failures and it does not | 7198 // handles unexpected data without causing assert failures and it does not |
7177 // do any heap allocations. This is useful when printing stack traces. | 7199 // do any heap allocations. This is useful when printing stack traces. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7233 | 7255 |
7234 // Layout description. | 7256 // Layout description. |
7235 static const int kLengthOffset = HeapObject::kHeaderSize; | 7257 static const int kLengthOffset = HeapObject::kHeaderSize; |
7236 static const int kHashFieldOffset = kLengthOffset + kPointerSize; | 7258 static const int kHashFieldOffset = kLengthOffset + kPointerSize; |
7237 static const int kSize = kHashFieldOffset + kPointerSize; | 7259 static const int kSize = kHashFieldOffset + kPointerSize; |
7238 | 7260 |
7239 // Maximum number of characters to consider when trying to convert a string | 7261 // Maximum number of characters to consider when trying to convert a string |
7240 // value into an array index. | 7262 // value into an array index. |
7241 static const int kMaxArrayIndexSize = 10; | 7263 static const int kMaxArrayIndexSize = 10; |
7242 | 7264 |
7243 // Max ASCII char code. | 7265 // Max char codes. |
7244 static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; | 7266 static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar; |
7245 static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; | 7267 static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar; |
7246 static const int kMaxUtf16CodeUnit = 0xffff; | 7268 static const int kMaxUtf16CodeUnit = 0xffff; |
7247 | 7269 |
7248 // Mask constant for checking if a string has a computed hash code | 7270 // Mask constant for checking if a string has a computed hash code |
7249 // and if it is an array index. The least significant bit indicates | 7271 // and if it is an array index. The least significant bit indicates |
7250 // whether a hash code has been computed. If the hash code has been | 7272 // whether a hash code has been computed. If the hash code has been |
7251 // computed the 2nd bit tells whether the string can be used as an | 7273 // computed the 2nd bit tells whether the string can be used as an |
7252 // array index. | 7274 // array index. |
7253 static const int kHashNotComputedMask = 1; | 7275 static const int kHashNotComputedMask = 1; |
7254 static const int kIsNotArrayIndexMask = 1 << 1; | 7276 static const int kIsNotArrayIndexMask = 1 << 1; |
7255 static const int kNofHashBitFields = 2; | 7277 static const int kNofHashBitFields = 2; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7320 int from, | 7342 int from, |
7321 int to); | 7343 int to); |
7322 | 7344 |
7323 // The return value may point to the first aligned word containing the | 7345 // The return value may point to the first aligned word containing the |
7324 // first non-ascii character, rather than directly to the non-ascii character. | 7346 // first non-ascii character, rather than directly to the non-ascii character. |
7325 // If the return value is >= the passed length, the entire string was ASCII. | 7347 // If the return value is >= the passed length, the entire string was ASCII. |
7326 static inline int NonAsciiStart(const char* chars, int length) { | 7348 static inline int NonAsciiStart(const char* chars, int length) { |
7327 const char* start = chars; | 7349 const char* start = chars; |
7328 const char* limit = chars + length; | 7350 const char* limit = chars + length; |
7329 #ifdef V8_HOST_CAN_READ_UNALIGNED | 7351 #ifdef V8_HOST_CAN_READ_UNALIGNED |
7330 ASSERT(kMaxAsciiCharCode == 0x7F); | 7352 ASSERT(unibrow::Utf8::kMaxOneByteChar == 0x7F); |
7331 const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80; | 7353 const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
7332 while (chars + sizeof(uintptr_t) <= limit) { | 7354 while (chars + sizeof(uintptr_t) <= limit) { |
7333 if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) { | 7355 if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) { |
7334 return static_cast<int>(chars - start); | 7356 return static_cast<int>(chars - start); |
7335 } | 7357 } |
7336 chars += sizeof(uintptr_t); | 7358 chars += sizeof(uintptr_t); |
7337 } | 7359 } |
7338 #endif | 7360 #endif |
7339 while (chars < limit) { | 7361 while (chars < limit) { |
7340 if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) { | 7362 if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { |
7341 return static_cast<int>(chars - start); | 7363 return static_cast<int>(chars - start); |
7342 } | 7364 } |
7343 ++chars; | 7365 ++chars; |
7344 } | 7366 } |
7345 return static_cast<int>(chars - start); | 7367 return static_cast<int>(chars - start); |
7346 } | 7368 } |
7347 | 7369 |
7348 static inline bool IsAscii(const char* chars, int length) { | 7370 static inline bool IsAscii(const char* chars, int length) { |
7349 return NonAsciiStart(chars, length) >= length; | 7371 return NonAsciiStart(chars, length) >= length; |
7350 } | 7372 } |
7351 | 7373 |
7352 static inline int NonAsciiStart(const uc16* chars, int length) { | 7374 static inline int NonOneByteStart(const uc16* chars, int length) { |
7353 const uc16* limit = chars + length; | 7375 const uc16* limit = chars + length; |
7354 const uc16* start = chars; | 7376 const uc16* start = chars; |
7355 while (chars < limit) { | 7377 while (chars < limit) { |
7356 if (*chars > kMaxAsciiCharCodeU) return static_cast<int>(chars - start); | 7378 if (*chars > kMaxOneByteCharCodeU) return static_cast<int>(chars - start); |
7357 ++chars; | 7379 ++chars; |
7358 } | 7380 } |
7359 return static_cast<int>(chars - start); | 7381 return static_cast<int>(chars - start); |
7360 } | 7382 } |
7361 | 7383 |
7362 static inline bool IsAscii(const uc16* chars, int length) { | 7384 static inline bool IsOneByte(const uc16* chars, int length) { |
7363 return NonAsciiStart(chars, length) >= length; | 7385 return NonOneByteStart(chars, length) >= length; |
7364 } | 7386 } |
7365 | 7387 |
7366 template<class Visitor, class ConsOp> | 7388 template<class Visitor, class ConsOp> |
7367 static inline void Visit(String* string, | 7389 static inline void Visit(String* string, |
7368 unsigned offset, | 7390 unsigned offset, |
7369 Visitor& visitor, | 7391 Visitor& visitor, |
7370 ConsOp& cons_op, | 7392 ConsOp& cons_op, |
7371 int32_t type, | 7393 int32_t type, |
7372 unsigned length); | 7394 unsigned length); |
7373 | 7395 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7418 public: | 7440 public: |
7419 static const bool kHasAsciiEncoding = true; | 7441 static const bool kHasAsciiEncoding = true; |
7420 | 7442 |
7421 // Dispatched behavior. | 7443 // Dispatched behavior. |
7422 inline uint16_t SeqOneByteStringGet(int index); | 7444 inline uint16_t SeqOneByteStringGet(int index); |
7423 inline void SeqOneByteStringSet(int index, uint16_t value); | 7445 inline void SeqOneByteStringSet(int index, uint16_t value); |
7424 | 7446 |
7425 // Get the address of the characters in this string. | 7447 // Get the address of the characters in this string. |
7426 inline Address GetCharsAddress(); | 7448 inline Address GetCharsAddress(); |
7427 | 7449 |
7450 // TODO(dcarney): remove GetChars and rename GetCharsU to GetChars. | |
7428 inline char* GetChars(); | 7451 inline char* GetChars(); |
7452 inline uint8_t* GetCharsU(); | |
7429 | 7453 |
7430 // Casting | 7454 // Casting |
7431 static inline SeqOneByteString* cast(Object* obj); | 7455 static inline SeqOneByteString* cast(Object* obj); |
7432 | 7456 |
7433 // Garbage collection support. This method is called by the | 7457 // Garbage collection support. This method is called by the |
7434 // garbage collector to compute the actual size of an AsciiString | 7458 // garbage collector to compute the actual size of an AsciiString |
7435 // instance. | 7459 // instance. |
7436 inline int SeqOneByteStringSize(InstanceType instance_type); | 7460 inline int SeqOneByteStringSize(InstanceType instance_type); |
7437 | 7461 |
7438 // Computes the size for an AsciiString instance of a given length. | 7462 // Computes the size for an AsciiString instance of a given length. |
(...skipping 1347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8786 } else { | 8810 } else { |
8787 value &= ~(1 << bit_position); | 8811 value &= ~(1 << bit_position); |
8788 } | 8812 } |
8789 return value; | 8813 return value; |
8790 } | 8814 } |
8791 }; | 8815 }; |
8792 | 8816 |
8793 } } // namespace v8::internal | 8817 } } // namespace v8::internal |
8794 | 8818 |
8795 #endif // V8_OBJECTS_H_ | 8819 #endif // V8_OBJECTS_H_ |
OLD | NEW |