Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 5675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5686 ASSERT(is_array_index()); | 5686 ASSERT(is_array_index()); |
| 5687 return array_index_; | 5687 return array_index_; |
| 5688 } | 5688 } |
| 5689 | 5689 |
| 5690 inline uint32_t GetHash(); | 5690 inline uint32_t GetHash(); |
| 5691 | 5691 |
| 5692 int length_; | 5692 int length_; |
| 5693 uint32_t raw_running_hash_; | 5693 uint32_t raw_running_hash_; |
| 5694 uint32_t array_index_; | 5694 uint32_t array_index_; |
| 5695 bool is_array_index_; | 5695 bool is_array_index_; |
| 5696 bool is_first_char_; | |
| 5697 bool is_valid_; | 5696 bool is_valid_; |
| 5698 friend class TwoCharHashTableKey; | 5697 friend class TwoCharHashTableKey; |
| 5699 }; | 5698 }; |
| 5700 | 5699 |
| 5701 | 5700 |
| 5702 // Calculates string hash. | 5701 // Calculates string hash. |
| 5703 template <typename schar> | 5702 template <typename schar> |
| 5704 inline uint32_t HashSequentialString(const schar* chars, int length); | 5703 inline uint32_t HashSequentialString(const schar* chars, int length); |
| 5705 | 5704 |
| 5706 | 5705 |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6143 static inline SeqString* cast(Object* obj); | 6142 static inline SeqString* cast(Object* obj); |
| 6144 | 6143 |
| 6145 // Layout description. | 6144 // Layout description. |
| 6146 static const int kHeaderSize = String::kSize; | 6145 static const int kHeaderSize = String::kSize; |
| 6147 | 6146 |
| 6148 private: | 6147 private: |
| 6149 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); | 6148 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 6150 }; | 6149 }; |
| 6151 | 6150 |
| 6152 | 6151 |
| 6153 // The AsciiString class captures sequential ascii string objects. | 6152 // The SeqAsciiString class captures sequential ASCII string objects. |
| 6154 // Each character in the AsciiString is an ascii character. | 6153 // Each character in the AsciiString is an ASCII character. |
| 6155 class SeqAsciiString: public SeqString { | 6154 class SeqAsciiString: public SeqString { |
| 6156 public: | 6155 public: |
| 6156 typedef char CharType; | |
| 6157 static const bool kHasAsciiEncoding = true; | 6157 static const bool kHasAsciiEncoding = true; |
| 6158 | 6158 |
| 6159 // Dispatched behavior. | 6159 // Dispatched behavior. |
| 6160 inline uint16_t SeqAsciiStringGet(int index); | 6160 inline uint16_t SeqAsciiStringGet(int index); |
| 6161 inline void SeqAsciiStringSet(int index, uint16_t value); | 6161 inline void SeqAsciiStringSet(int index, uint16_t value); |
| 6162 | 6162 |
| 6163 // Get the address of the characters in this string. | 6163 // Get the address of the characters in this string. |
| 6164 inline Address GetCharsAddress(); | 6164 inline Address GetCharsAddress(); |
| 6165 | 6165 |
| 6166 inline char* GetChars(); | 6166 inline char* GetChars(); |
| 6167 | 6167 |
| 6168 // Casting | 6168 // Casting |
| 6169 static inline SeqAsciiString* cast(Object* obj); | 6169 static inline SeqAsciiString* cast(Object* obj); |
| 6170 | 6170 |
| 6171 bool IsSeqAsciiString() { | |
|
Rico
2011/09/23 07:06:52
Why this, we can always just call IsSequentialAsci
Lasse Reichstein
2011/09/23 09:54:39
As discussed offline, this is to allow templated f
| |
| 6172 ASSERT(this->Object::IsSeqAsciiString()); | |
| 6173 return true; | |
| 6174 } | |
| 6175 | |
| 6171 // Garbage collection support. This method is called by the | 6176 // Garbage collection support. This method is called by the |
| 6172 // garbage collector to compute the actual size of an AsciiString | 6177 // garbage collector to compute the actual size of an AsciiString |
| 6173 // instance. | 6178 // instance. |
| 6174 inline int SeqAsciiStringSize(InstanceType instance_type); | 6179 inline int SeqAsciiStringSize(InstanceType instance_type); |
| 6175 | 6180 |
| 6176 // Computes the size for an AsciiString instance of a given length. | 6181 // Computes the size for an AsciiString instance of a given length. |
| 6177 static int SizeFor(int length) { | 6182 static int SizeFor(int length) { |
| 6178 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); | 6183 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
| 6179 } | 6184 } |
| 6180 | 6185 |
| 6181 // Maximal memory usage for a single sequential ASCII string. | 6186 // Maximal memory usage for a single sequential ASCII string. |
| 6182 static const int kMaxSize = 512 * MB - 1; | 6187 static const int kMaxSize = 512 * MB - 1; |
| 6183 // Maximal length of a single sequential ASCII string. | 6188 // Maximal length of a single sequential ASCII string. |
| 6184 // Q.v. String::kMaxLength which is the maximal size of concatenated strings. | 6189 // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 6185 static const int kMaxLength = (kMaxSize - kHeaderSize); | 6190 static const int kMaxLength = (kMaxSize - kHeaderSize); |
| 6186 | 6191 |
| 6187 // Support for StringInputBuffer. | 6192 // Support for StringInputBuffer. |
| 6188 inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, | 6193 inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6189 unsigned* offset, | 6194 unsigned* offset, |
| 6190 unsigned chars); | 6195 unsigned chars); |
| 6191 inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, | 6196 inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
| 6192 unsigned* offset, | 6197 unsigned* offset, |
| 6193 unsigned chars); | 6198 unsigned chars); |
| 6194 | 6199 |
| 6195 private: | 6200 private: |
| 6196 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); | 6201 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
| 6197 }; | 6202 }; |
| 6198 | 6203 |
| 6199 | 6204 |
| 6200 // The TwoByteString class captures sequential unicode string objects. | 6205 // The SeqTwoByteString class captures sequential unicode string objects. |
| 6201 // Each character in the TwoByteString is a two-byte uint16_t. | 6206 // Each character in the TwoByteString is a two-byte uint16_t. |
| 6202 class SeqTwoByteString: public SeqString { | 6207 class SeqTwoByteString: public SeqString { |
| 6203 public: | 6208 public: |
| 6209 typedef uc16 CharType; | |
| 6210 | |
| 6204 static const bool kHasAsciiEncoding = false; | 6211 static const bool kHasAsciiEncoding = false; |
| 6205 | 6212 |
| 6206 // Dispatched behavior. | 6213 // Dispatched behavior. |
| 6207 inline uint16_t SeqTwoByteStringGet(int index); | 6214 inline uint16_t SeqTwoByteStringGet(int index); |
| 6208 inline void SeqTwoByteStringSet(int index, uint16_t value); | 6215 inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 6209 | 6216 |
| 6210 // Get the address of the characters in this string. | 6217 // Get the address of the characters in this string. |
| 6211 inline Address GetCharsAddress(); | 6218 inline Address GetCharsAddress(); |
| 6212 | 6219 |
| 6213 inline uc16* GetChars(); | 6220 inline uc16* GetChars(); |
| 6214 | 6221 |
| 6215 // For regexp code. | 6222 // For regexp code. |
| 6216 const uint16_t* SeqTwoByteStringGetData(unsigned start); | 6223 const uint16_t* SeqTwoByteStringGetData(unsigned start); |
| 6217 | 6224 |
| 6218 // Casting | 6225 // Casting |
| 6219 static inline SeqTwoByteString* cast(Object* obj); | 6226 static inline SeqTwoByteString* cast(Object* obj); |
| 6227 bool IsSeqTwoByteString() { | |
| 6228 ASSERT(this->Object::IsSeqTwoByteString()); | |
|
Rico
2011/09/23 07:06:52
Same question as for ascii
Lasse Reichstein
2011/09/23 09:54:39
Same answer.
| |
| 6229 return true; | |
| 6230 } | |
| 6220 | 6231 |
| 6221 // Garbage collection support. This method is called by the | 6232 // Garbage collection support. This method is called by the |
| 6222 // garbage collector to compute the actual size of a TwoByteString | 6233 // garbage collector to compute the actual size of a TwoByteString |
| 6223 // instance. | 6234 // instance. |
| 6224 inline int SeqTwoByteStringSize(InstanceType instance_type); | 6235 inline int SeqTwoByteStringSize(InstanceType instance_type); |
| 6225 | 6236 |
| 6226 // Computes the size for a TwoByteString instance of a given length. | 6237 // Computes the size for a TwoByteString instance of a given length. |
| 6227 static int SizeFor(int length) { | 6238 static int SizeFor(int length) { |
| 6228 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); | 6239 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
| 6229 } | 6240 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6379 | 6390 |
| 6380 private: | 6391 private: |
| 6381 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); | 6392 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 6382 }; | 6393 }; |
| 6383 | 6394 |
| 6384 | 6395 |
| 6385 // The ExternalAsciiString class is an external string backed by an | 6396 // The ExternalAsciiString class is an external string backed by an |
| 6386 // ASCII string. | 6397 // ASCII string. |
| 6387 class ExternalAsciiString: public ExternalString { | 6398 class ExternalAsciiString: public ExternalString { |
| 6388 public: | 6399 public: |
| 6400 typedef char CharType; | |
| 6401 | |
| 6389 static const bool kHasAsciiEncoding = true; | 6402 static const bool kHasAsciiEncoding = true; |
| 6390 | 6403 |
| 6391 typedef v8::String::ExternalAsciiStringResource Resource; | 6404 typedef v8::String::ExternalAsciiStringResource Resource; |
| 6392 | 6405 |
| 6393 // The underlying resource. | 6406 // The underlying resource. |
| 6394 inline const Resource* resource(); | 6407 inline const Resource* resource(); |
| 6395 inline void set_resource(const Resource* buffer); | 6408 inline void set_resource(const Resource* buffer); |
| 6396 | 6409 |
| 6397 // Dispatched behavior. | 6410 // Dispatched behavior. |
| 6398 uint16_t ExternalAsciiStringGet(int index); | 6411 uint16_t ExternalAsciiStringGet(int index); |
| 6399 | 6412 |
| 6400 // Casting. | 6413 // Casting. |
| 6401 static inline ExternalAsciiString* cast(Object* obj); | 6414 static inline ExternalAsciiString* cast(Object* obj); |
| 6415 bool IsExternalAsciiString() { | |
| 6416 ASSERT(this->Object::IsExternalAsciiString()); | |
| 6417 return true; | |
| 6418 } | |
| 6402 | 6419 |
| 6403 // Garbage collection support. | 6420 // Garbage collection support. |
| 6404 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); | 6421 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); |
| 6405 | 6422 |
| 6406 template<typename StaticVisitor> | 6423 template<typename StaticVisitor> |
| 6407 inline void ExternalAsciiStringIterateBody(); | 6424 inline void ExternalAsciiStringIterateBody(); |
| 6408 | 6425 |
| 6409 // Support for StringInputBuffer. | 6426 // Support for StringInputBuffer. |
| 6410 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, | 6427 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
| 6411 unsigned* offset, | 6428 unsigned* offset, |
| 6412 unsigned chars); | 6429 unsigned chars); |
| 6413 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, | 6430 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6414 unsigned* offset, | 6431 unsigned* offset, |
| 6415 unsigned chars); | 6432 unsigned chars); |
| 6416 | 6433 |
| 6417 private: | 6434 private: |
| 6418 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); | 6435 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
| 6419 }; | 6436 }; |
| 6420 | 6437 |
| 6421 | 6438 |
| 6422 // The ExternalTwoByteString class is an external string backed by a UTF-16 | 6439 // The ExternalTwoByteString class is an external string backed by a 16-bit |
| 6423 // encoded string. | 6440 // character sequence. |
| 6424 class ExternalTwoByteString: public ExternalString { | 6441 class ExternalTwoByteString: public ExternalString { |
| 6425 public: | 6442 public: |
| 6443 typedef uc16 CharType; | |
| 6426 static const bool kHasAsciiEncoding = false; | 6444 static const bool kHasAsciiEncoding = false; |
| 6427 | 6445 |
| 6428 typedef v8::String::ExternalStringResource Resource; | 6446 typedef v8::String::ExternalStringResource Resource; |
| 6429 | 6447 |
| 6430 // The underlying string resource. | 6448 // The underlying string resource. |
| 6431 inline const Resource* resource(); | 6449 inline const Resource* resource(); |
| 6432 inline void set_resource(const Resource* buffer); | 6450 inline void set_resource(const Resource* buffer); |
| 6433 | 6451 |
| 6434 // Dispatched behavior. | 6452 // Dispatched behavior. |
| 6435 uint16_t ExternalTwoByteStringGet(int index); | 6453 uint16_t ExternalTwoByteStringGet(int index); |
| 6436 | 6454 |
| 6437 // For regexp code. | 6455 // For regexp code. |
| 6438 const uint16_t* ExternalTwoByteStringGetData(unsigned start); | 6456 const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
| 6439 | 6457 |
| 6440 // Casting. | 6458 // Casting. |
| 6441 static inline ExternalTwoByteString* cast(Object* obj); | 6459 static inline ExternalTwoByteString* cast(Object* obj); |
| 6460 bool IsExternalTwoByteString() { | |
| 6461 ASSERT(this->Object::IsExternalTwoByteString()); | |
| 6462 return true; | |
| 6463 } | |
| 6442 | 6464 |
| 6443 // Garbage collection support. | 6465 // Garbage collection support. |
| 6444 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); | 6466 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); |
| 6445 | 6467 |
| 6446 template<typename StaticVisitor> | 6468 template<typename StaticVisitor> |
| 6447 inline void ExternalTwoByteStringIterateBody(); | 6469 inline void ExternalTwoByteStringIterateBody(); |
| 6448 | 6470 |
| 6449 | 6471 |
| 6450 // Support for StringInputBuffer. | 6472 // Support for StringInputBuffer. |
| 6451 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, | 6473 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7403 } else { | 7425 } else { |
| 7404 value &= ~(1 << bit_position); | 7426 value &= ~(1 << bit_position); |
| 7405 } | 7427 } |
| 7406 return value; | 7428 return value; |
| 7407 } | 7429 } |
| 7408 }; | 7430 }; |
| 7409 | 7431 |
| 7410 } } // namespace v8::internal | 7432 } } // namespace v8::internal |
| 7411 | 7433 |
| 7412 #endif // V8_OBJECTS_H_ | 7434 #endif // V8_OBJECTS_H_ |
| OLD | NEW |