| 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 5737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5748 ASSERT(is_array_index()); | 5748 ASSERT(is_array_index()); |
| 5749 return array_index_; | 5749 return array_index_; |
| 5750 } | 5750 } |
| 5751 | 5751 |
| 5752 inline uint32_t GetHash(); | 5752 inline uint32_t GetHash(); |
| 5753 | 5753 |
| 5754 int length_; | 5754 int length_; |
| 5755 uint32_t raw_running_hash_; | 5755 uint32_t raw_running_hash_; |
| 5756 uint32_t array_index_; | 5756 uint32_t array_index_; |
| 5757 bool is_array_index_; | 5757 bool is_array_index_; |
| 5758 bool is_first_char_; | |
| 5759 bool is_valid_; | 5758 bool is_valid_; |
| 5760 friend class TwoCharHashTableKey; | 5759 friend class TwoCharHashTableKey; |
| 5761 }; | 5760 }; |
| 5762 | 5761 |
| 5763 | 5762 |
| 5764 // Calculates string hash. | 5763 // Calculates string hash. |
| 5765 template <typename schar> | 5764 template <typename schar> |
| 5766 inline uint32_t HashSequentialString(const schar* chars, int length); | 5765 inline uint32_t HashSequentialString(const schar* chars, int length); |
| 5767 | 5766 |
| 5768 | 5767 |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6200 | 6199 |
| 6201 // The SeqString abstract class captures sequential string values. | 6200 // The SeqString abstract class captures sequential string values. |
| 6202 class SeqString: public String { | 6201 class SeqString: public String { |
| 6203 public: | 6202 public: |
| 6204 // Casting. | 6203 // Casting. |
| 6205 static inline SeqString* cast(Object* obj); | 6204 static inline SeqString* cast(Object* obj); |
| 6206 | 6205 |
| 6207 // Layout description. | 6206 // Layout description. |
| 6208 static const int kHeaderSize = String::kSize; | 6207 static const int kHeaderSize = String::kSize; |
| 6209 | 6208 |
| 6209 // Shortcuts for templates that know their string-type exactly. |
| 6210 bool IsExternalAsciiString() { |
| 6211 return false; |
| 6212 } |
| 6213 bool IsExternalTwoByteString() { |
| 6214 return false; |
| 6215 } |
| 6216 |
| 6217 |
| 6210 private: | 6218 private: |
| 6211 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); | 6219 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 6212 }; | 6220 }; |
| 6213 | 6221 |
| 6214 | 6222 |
| 6215 // The AsciiString class captures sequential ascii string objects. | 6223 // The SeqAsciiString class captures sequential ASCII string objects. |
| 6216 // Each character in the AsciiString is an ascii character. | 6224 // Each character in the AsciiString is an ASCII character. |
| 6217 class SeqAsciiString: public SeqString { | 6225 class SeqAsciiString: public SeqString { |
| 6218 public: | 6226 public: |
| 6227 typedef char CharType; |
| 6219 static const bool kHasAsciiEncoding = true; | 6228 static const bool kHasAsciiEncoding = true; |
| 6220 | 6229 |
| 6221 // Dispatched behavior. | 6230 // Dispatched behavior. |
| 6222 inline uint16_t SeqAsciiStringGet(int index); | 6231 inline uint16_t SeqAsciiStringGet(int index); |
| 6223 inline void SeqAsciiStringSet(int index, uint16_t value); | 6232 inline void SeqAsciiStringSet(int index, uint16_t value); |
| 6224 | 6233 |
| 6225 // Get the address of the characters in this string. | 6234 // Get the address of the characters in this string. |
| 6226 inline Address GetCharsAddress(); | 6235 inline Address GetCharsAddress(); |
| 6227 | 6236 |
| 6228 inline char* GetChars(); | 6237 inline char* GetChars(); |
| 6229 | 6238 |
| 6230 // Casting | 6239 // Casting |
| 6231 static inline SeqAsciiString* cast(Object* obj); | 6240 static inline SeqAsciiString* cast(Object* obj); |
| 6232 | 6241 |
| 6242 bool IsSeqAsciiString() { |
| 6243 ASSERT(this->Object::IsSeqAsciiString()); |
| 6244 return true; |
| 6245 } |
| 6246 bool IsSeqTwoByteString() { |
| 6247 ASSERT(this->Object::IsSeqAsciiString()); |
| 6248 return false; |
| 6249 } |
| 6250 |
| 6233 // Garbage collection support. This method is called by the | 6251 // Garbage collection support. This method is called by the |
| 6234 // garbage collector to compute the actual size of an AsciiString | 6252 // garbage collector to compute the actual size of an AsciiString |
| 6235 // instance. | 6253 // instance. |
| 6236 inline int SeqAsciiStringSize(InstanceType instance_type); | 6254 inline int SeqAsciiStringSize(InstanceType instance_type); |
| 6237 | 6255 |
| 6238 // Computes the size for an AsciiString instance of a given length. | 6256 // Computes the size for an AsciiString instance of a given length. |
| 6239 static int SizeFor(int length) { | 6257 static int SizeFor(int length) { |
| 6240 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); | 6258 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
| 6241 } | 6259 } |
| 6242 | 6260 |
| 6243 // Maximal memory usage for a single sequential ASCII string. | 6261 // Maximal memory usage for a single sequential ASCII string. |
| 6244 static const int kMaxSize = 512 * MB - 1; | 6262 static const int kMaxSize = 512 * MB - 1; |
| 6245 // Maximal length of a single sequential ASCII string. | 6263 // Maximal length of a single sequential ASCII string. |
| 6246 // Q.v. String::kMaxLength which is the maximal size of concatenated strings. | 6264 // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 6247 static const int kMaxLength = (kMaxSize - kHeaderSize); | 6265 static const int kMaxLength = (kMaxSize - kHeaderSize); |
| 6248 | 6266 |
| 6249 // Support for StringInputBuffer. | 6267 // Support for StringInputBuffer. |
| 6250 inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, | 6268 inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6251 unsigned* offset, | 6269 unsigned* offset, |
| 6252 unsigned chars); | 6270 unsigned chars); |
| 6253 inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, | 6271 inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
| 6254 unsigned* offset, | 6272 unsigned* offset, |
| 6255 unsigned chars); | 6273 unsigned chars); |
| 6256 | 6274 |
| 6257 private: | 6275 private: |
| 6258 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); | 6276 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
| 6259 }; | 6277 }; |
| 6260 | 6278 |
| 6261 | 6279 |
| 6262 // The TwoByteString class captures sequential unicode string objects. | 6280 // The SeqTwoByteString class captures sequential unicode string objects. |
| 6263 // Each character in the TwoByteString is a two-byte uint16_t. | 6281 // Each character in the TwoByteString is a two-byte uint16_t. |
| 6264 class SeqTwoByteString: public SeqString { | 6282 class SeqTwoByteString: public SeqString { |
| 6265 public: | 6283 public: |
| 6284 typedef uc16 CharType; |
| 6285 |
| 6266 static const bool kHasAsciiEncoding = false; | 6286 static const bool kHasAsciiEncoding = false; |
| 6267 | 6287 |
| 6268 // Dispatched behavior. | 6288 // Dispatched behavior. |
| 6269 inline uint16_t SeqTwoByteStringGet(int index); | 6289 inline uint16_t SeqTwoByteStringGet(int index); |
| 6270 inline void SeqTwoByteStringSet(int index, uint16_t value); | 6290 inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 6271 | 6291 |
| 6272 // Get the address of the characters in this string. | 6292 // Get the address of the characters in this string. |
| 6273 inline Address GetCharsAddress(); | 6293 inline Address GetCharsAddress(); |
| 6274 | 6294 |
| 6275 inline uc16* GetChars(); | 6295 inline uc16* GetChars(); |
| 6276 | 6296 |
| 6277 // For regexp code. | 6297 // For regexp code. |
| 6278 const uint16_t* SeqTwoByteStringGetData(unsigned start); | 6298 const uint16_t* SeqTwoByteStringGetData(unsigned start); |
| 6279 | 6299 |
| 6280 // Casting | 6300 // Casting |
| 6281 static inline SeqTwoByteString* cast(Object* obj); | 6301 static inline SeqTwoByteString* cast(Object* obj); |
| 6302 bool IsSeqTwoByteString() { |
| 6303 ASSERT(this->Object::IsSeqTwoByteString()); |
| 6304 return true; |
| 6305 } |
| 6306 bool IsSeqAsciiString() { |
| 6307 ASSERT(this->Object::IsSeqTwoByteString()); |
| 6308 return false; |
| 6309 } |
| 6282 | 6310 |
| 6283 // Garbage collection support. This method is called by the | 6311 // Garbage collection support. This method is called by the |
| 6284 // garbage collector to compute the actual size of a TwoByteString | 6312 // garbage collector to compute the actual size of a TwoByteString |
| 6285 // instance. | 6313 // instance. |
| 6286 inline int SeqTwoByteStringSize(InstanceType instance_type); | 6314 inline int SeqTwoByteStringSize(InstanceType instance_type); |
| 6287 | 6315 |
| 6288 // Computes the size for a TwoByteString instance of a given length. | 6316 // Computes the size for a TwoByteString instance of a given length. |
| 6289 static int SizeFor(int length) { | 6317 static int SizeFor(int length) { |
| 6290 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); | 6318 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
| 6291 } | 6319 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6432 public: | 6460 public: |
| 6433 // Casting | 6461 // Casting |
| 6434 static inline ExternalString* cast(Object* obj); | 6462 static inline ExternalString* cast(Object* obj); |
| 6435 | 6463 |
| 6436 // Layout description. | 6464 // Layout description. |
| 6437 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); | 6465 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 6438 static const int kSize = kResourceOffset + kPointerSize; | 6466 static const int kSize = kResourceOffset + kPointerSize; |
| 6439 | 6467 |
| 6440 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); | 6468 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); |
| 6441 | 6469 |
| 6470 // Shortcuts for templates that know their string type exactly. |
| 6471 bool IsSeqAsciiString() { |
| 6472 return false; |
| 6473 } |
| 6474 bool IsSeqTwoByteString() { |
| 6475 return false; |
| 6476 } |
| 6477 |
| 6442 private: | 6478 private: |
| 6443 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); | 6479 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 6444 }; | 6480 }; |
| 6445 | 6481 |
| 6446 | 6482 |
| 6447 // The ExternalAsciiString class is an external string backed by an | 6483 // The ExternalAsciiString class is an external string backed by an |
| 6448 // ASCII string. | 6484 // ASCII string. |
| 6449 class ExternalAsciiString: public ExternalString { | 6485 class ExternalAsciiString: public ExternalString { |
| 6450 public: | 6486 public: |
| 6487 typedef char CharType; |
| 6488 |
| 6451 static const bool kHasAsciiEncoding = true; | 6489 static const bool kHasAsciiEncoding = true; |
| 6452 | 6490 |
| 6453 typedef v8::String::ExternalAsciiStringResource Resource; | 6491 typedef v8::String::ExternalAsciiStringResource Resource; |
| 6454 | 6492 |
| 6455 // The underlying resource. | 6493 // The underlying resource. |
| 6456 inline const Resource* resource(); | 6494 inline const Resource* resource(); |
| 6457 inline void set_resource(const Resource* buffer); | 6495 inline void set_resource(const Resource* buffer); |
| 6458 | 6496 |
| 6459 // Dispatched behavior. | 6497 // Dispatched behavior. |
| 6460 uint16_t ExternalAsciiStringGet(int index); | 6498 uint16_t ExternalAsciiStringGet(int index); |
| 6461 | 6499 |
| 6462 // Casting. | 6500 // Casting. |
| 6463 static inline ExternalAsciiString* cast(Object* obj); | 6501 static inline ExternalAsciiString* cast(Object* obj); |
| 6502 bool IsExternalAsciiString() { |
| 6503 ASSERT(this->Object::IsExternalAsciiString()); |
| 6504 return true; |
| 6505 } |
| 6506 bool IsExternalTwoByteString() { |
| 6507 ASSERT(this->Object::IsExternalAsciiString()); |
| 6508 return false; |
| 6509 } |
| 6464 | 6510 |
| 6465 // Garbage collection support. | 6511 // Garbage collection support. |
| 6466 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); | 6512 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); |
| 6467 | 6513 |
| 6468 template<typename StaticVisitor> | 6514 template<typename StaticVisitor> |
| 6469 inline void ExternalAsciiStringIterateBody(); | 6515 inline void ExternalAsciiStringIterateBody(); |
| 6470 | 6516 |
| 6471 // Support for StringInputBuffer. | 6517 // Support for StringInputBuffer. |
| 6472 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, | 6518 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
| 6473 unsigned* offset, | 6519 unsigned* offset, |
| 6474 unsigned chars); | 6520 unsigned chars); |
| 6475 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, | 6521 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6476 unsigned* offset, | 6522 unsigned* offset, |
| 6477 unsigned chars); | 6523 unsigned chars); |
| 6478 | 6524 |
| 6479 private: | 6525 private: |
| 6480 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); | 6526 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
| 6481 }; | 6527 }; |
| 6482 | 6528 |
| 6483 | 6529 |
| 6484 // The ExternalTwoByteString class is an external string backed by a UTF-16 | 6530 // The ExternalTwoByteString class is an external string backed by a 16-bit |
| 6485 // encoded string. | 6531 // character sequence. |
| 6486 class ExternalTwoByteString: public ExternalString { | 6532 class ExternalTwoByteString: public ExternalString { |
| 6487 public: | 6533 public: |
| 6534 typedef uc16 CharType; |
| 6488 static const bool kHasAsciiEncoding = false; | 6535 static const bool kHasAsciiEncoding = false; |
| 6489 | 6536 |
| 6490 typedef v8::String::ExternalStringResource Resource; | 6537 typedef v8::String::ExternalStringResource Resource; |
| 6491 | 6538 |
| 6492 // The underlying string resource. | 6539 // The underlying string resource. |
| 6493 inline const Resource* resource(); | 6540 inline const Resource* resource(); |
| 6494 inline void set_resource(const Resource* buffer); | 6541 inline void set_resource(const Resource* buffer); |
| 6495 | 6542 |
| 6496 // Dispatched behavior. | 6543 // Dispatched behavior. |
| 6497 uint16_t ExternalTwoByteStringGet(int index); | 6544 uint16_t ExternalTwoByteStringGet(int index); |
| 6498 | 6545 |
| 6499 // For regexp code. | 6546 // For regexp code. |
| 6500 const uint16_t* ExternalTwoByteStringGetData(unsigned start); | 6547 const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
| 6501 | 6548 |
| 6502 // Casting. | 6549 // Casting. |
| 6503 static inline ExternalTwoByteString* cast(Object* obj); | 6550 static inline ExternalTwoByteString* cast(Object* obj); |
| 6551 bool IsExternalTwoByteString() { |
| 6552 ASSERT(this->Object::IsExternalTwoByteString()); |
| 6553 return true; |
| 6554 } |
| 6555 bool IsExternalAsciiString() { |
| 6556 ASSERT(this->Object::IsExternalTwoByteString()); |
| 6557 return false; |
| 6558 } |
| 6504 | 6559 |
| 6505 // Garbage collection support. | 6560 // Garbage collection support. |
| 6506 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); | 6561 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); |
| 6507 | 6562 |
| 6508 template<typename StaticVisitor> | 6563 template<typename StaticVisitor> |
| 6509 inline void ExternalTwoByteStringIterateBody(); | 6564 inline void ExternalTwoByteStringIterateBody(); |
| 6510 | 6565 |
| 6511 | 6566 |
| 6512 // Support for StringInputBuffer. | 6567 // Support for StringInputBuffer. |
| 6513 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, | 6568 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| (...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7494 } else { | 7549 } else { |
| 7495 value &= ~(1 << bit_position); | 7550 value &= ~(1 << bit_position); |
| 7496 } | 7551 } |
| 7497 return value; | 7552 return value; |
| 7498 } | 7553 } |
| 7499 }; | 7554 }; |
| 7500 | 7555 |
| 7501 } } // namespace v8::internal | 7556 } } // namespace v8::internal |
| 7502 | 7557 |
| 7503 #endif // V8_OBJECTS_H_ | 7558 #endif // V8_OBJECTS_H_ |
| OLD | NEW |