Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
| 6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
| 7 | 7 |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/dart.h" | 9 #include "vm/dart.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 2285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2296 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } | 2296 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } |
| 2297 | 2297 |
| 2298 virtual intptr_t Hash() const; | 2298 virtual intptr_t Hash() const; |
| 2299 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } | 2299 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } |
| 2300 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); | 2300 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); |
| 2301 static intptr_t Hash(const uint8_t* characters, intptr_t len); | 2301 static intptr_t Hash(const uint8_t* characters, intptr_t len); |
| 2302 static intptr_t Hash(const uint16_t* characters, intptr_t len); | 2302 static intptr_t Hash(const uint16_t* characters, intptr_t len); |
| 2303 static intptr_t Hash(const uint32_t* characters, intptr_t len); | 2303 static intptr_t Hash(const uint32_t* characters, intptr_t len); |
| 2304 | 2304 |
| 2305 virtual int32_t CharAt(intptr_t index) const; | 2305 virtual int32_t CharAt(intptr_t index) const; |
| 2306 virtual void SetCharAt(intptr_t index, int32_t value) const; | |
|
Ivan Posva
2011/10/18 22:01:13
This should only be accessible to very few limited
cshapiro
2011/10/20 02:35:05
I have added a Transform method that is safe to us
Ivan Posva
2011/10/21 14:03:37
Looks a lot cleaner.
| |
| 2306 | 2307 |
| 2307 bool Equals(const String& str, intptr_t begin_index, intptr_t len) const; | 2308 bool Equals(const String& str, intptr_t begin_index, intptr_t len) const; |
| 2308 bool Equals(const char* str) const; | 2309 bool Equals(const char* str) const; |
| 2309 bool Equals(const uint8_t* characters, intptr_t len) const; | 2310 bool Equals(const uint8_t* characters, intptr_t len) const; |
| 2310 bool Equals(const uint16_t* characters, intptr_t len) const; | 2311 bool Equals(const uint16_t* characters, intptr_t len) const; |
| 2311 bool Equals(const uint32_t* characters, intptr_t len) const; | 2312 bool Equals(const uint32_t* characters, intptr_t len) const; |
| 2312 | 2313 |
| 2313 virtual bool Equals(const Instance& other) const; | 2314 virtual bool Equals(const Instance& other) const; |
| 2314 | 2315 |
| 2315 intptr_t CompareTo(const String& other) const; | 2316 intptr_t CompareTo(const String& other) const; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2357 Heap::Space space = Heap::kNew); | 2358 Heap::Space space = Heap::kNew); |
| 2358 | 2359 |
| 2359 static RawString* SubString(const String& str, | 2360 static RawString* SubString(const String& str, |
| 2360 intptr_t begin_index, | 2361 intptr_t begin_index, |
| 2361 Heap::Space space = Heap::kNew); | 2362 Heap::Space space = Heap::kNew); |
| 2362 static RawString* SubString(const String& str, | 2363 static RawString* SubString(const String& str, |
| 2363 intptr_t begin_index, | 2364 intptr_t begin_index, |
| 2364 intptr_t length, | 2365 intptr_t length, |
| 2365 Heap::Space space = Heap::kNew); | 2366 Heap::Space space = Heap::kNew); |
| 2366 | 2367 |
| 2368 static RawString* ToUpperCase(const String& str, | |
| 2369 Heap::Space space = Heap::kNew); | |
| 2370 static RawString* ToLowerCase(const String& str, | |
| 2371 Heap::Space space = Heap::kNew); | |
| 2372 | |
| 2367 static RawString* NewSymbol(const char* str); | 2373 static RawString* NewSymbol(const char* str); |
| 2368 template<typename T> | 2374 template<typename T> |
| 2369 static RawString* NewSymbol(const T* characters, intptr_t len); | 2375 static RawString* NewSymbol(const T* characters, intptr_t len); |
| 2370 static RawString* NewSymbol(const String& str); | 2376 static RawString* NewSymbol(const String& str); |
| 2371 static RawString* NewSymbol(const String& str, | 2377 static RawString* NewSymbol(const String& str, |
| 2372 intptr_t begin_index, | 2378 intptr_t begin_index, |
| 2373 intptr_t length); | 2379 intptr_t length); |
| 2374 | 2380 |
| 2375 protected: | 2381 protected: |
| 2376 bool HasHash() const { | 2382 bool HasHash() const { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 2392 | 2398 |
| 2393 HEAP_OBJECT_IMPLEMENTATION(String, Instance); | 2399 HEAP_OBJECT_IMPLEMENTATION(String, Instance); |
| 2394 }; | 2400 }; |
| 2395 | 2401 |
| 2396 | 2402 |
| 2397 class OneByteString : public String { | 2403 class OneByteString : public String { |
| 2398 public: | 2404 public: |
| 2399 virtual int32_t CharAt(intptr_t index) const { | 2405 virtual int32_t CharAt(intptr_t index) const { |
| 2400 return *CharAddr(index); | 2406 return *CharAddr(index); |
| 2401 } | 2407 } |
| 2408 virtual void SetCharAt(intptr_t index, int32_t value) const { | |
| 2409 ASSERT(value <= 0xFF); | |
| 2410 *CharAddr(index) = value; | |
| 2411 } | |
| 2402 | 2412 |
| 2403 static intptr_t InstanceSize() { | 2413 static intptr_t InstanceSize() { |
| 2404 ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_)); | 2414 ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_)); |
| 2405 return 0; | 2415 return 0; |
| 2406 } | 2416 } |
| 2407 | 2417 |
| 2408 static intptr_t InstanceSize(intptr_t len) { | 2418 static intptr_t InstanceSize(intptr_t len) { |
| 2409 return RoundedAllocationSize(sizeof(RawOneByteString) + len); | 2419 return RoundedAllocationSize(sizeof(RawOneByteString) + len); |
| 2410 } | 2420 } |
| 2411 | 2421 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2446 friend class Class; | 2456 friend class Class; |
| 2447 friend class String; | 2457 friend class String; |
| 2448 }; | 2458 }; |
| 2449 | 2459 |
| 2450 | 2460 |
| 2451 class TwoByteString : public String { | 2461 class TwoByteString : public String { |
| 2452 public: | 2462 public: |
| 2453 virtual int32_t CharAt(intptr_t index) const { | 2463 virtual int32_t CharAt(intptr_t index) const { |
| 2454 return *CharAddr(index); | 2464 return *CharAddr(index); |
| 2455 } | 2465 } |
| 2466 virtual void SetCharAt(intptr_t index, int32_t value) const { | |
| 2467 ASSERT(value <= 0xFFFF); | |
| 2468 *CharAddr(index) = value; | |
| 2469 } | |
| 2456 | 2470 |
| 2457 static intptr_t InstanceSize() { | 2471 static intptr_t InstanceSize() { |
| 2458 ASSERT(sizeof(RawTwoByteString) == OFFSET_OF(RawTwoByteString, data_)); | 2472 ASSERT(sizeof(RawTwoByteString) == OFFSET_OF(RawTwoByteString, data_)); |
| 2459 return 0; | 2473 return 0; |
| 2460 } | 2474 } |
| 2461 | 2475 |
| 2462 static intptr_t InstanceSize(intptr_t len) { | 2476 static intptr_t InstanceSize(intptr_t len) { |
| 2463 return RoundedAllocationSize(sizeof(RawTwoByteString) + (2 * len)); | 2477 return RoundedAllocationSize(sizeof(RawTwoByteString) + (2 * len)); |
| 2464 } | 2478 } |
| 2465 | 2479 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2496 friend class Class; | 2510 friend class Class; |
| 2497 friend class String; | 2511 friend class String; |
| 2498 }; | 2512 }; |
| 2499 | 2513 |
| 2500 | 2514 |
| 2501 class FourByteString : public String { | 2515 class FourByteString : public String { |
| 2502 public: | 2516 public: |
| 2503 virtual int32_t CharAt(intptr_t index) const { | 2517 virtual int32_t CharAt(intptr_t index) const { |
| 2504 return *CharAddr(index); | 2518 return *CharAddr(index); |
| 2505 } | 2519 } |
| 2520 virtual void SetCharAt(intptr_t index, int32_t value) const { | |
| 2521 ASSERT(value <= 0x10FFFF); | |
| 2522 *CharAddr(index) = value; | |
| 2523 } | |
| 2506 | 2524 |
| 2507 static intptr_t InstanceSize() { | 2525 static intptr_t InstanceSize() { |
| 2508 ASSERT(sizeof(RawFourByteString) == OFFSET_OF(RawFourByteString, data_)); | 2526 ASSERT(sizeof(RawFourByteString) == OFFSET_OF(RawFourByteString, data_)); |
| 2509 return 0; | 2527 return 0; |
| 2510 } | 2528 } |
| 2511 | 2529 |
| 2512 static intptr_t InstanceSize(intptr_t len) { | 2530 static intptr_t InstanceSize(intptr_t len) { |
| 2513 return RoundedAllocationSize(sizeof(RawFourByteString) + (4 * len)); | 2531 return RoundedAllocationSize(sizeof(RawFourByteString) + (4 * len)); |
| 2514 } | 2532 } |
| 2515 | 2533 |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2876 } | 2894 } |
| 2877 | 2895 |
| 2878 | 2896 |
| 2879 void Context::SetAt(intptr_t index, const Instance& value) const { | 2897 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 2880 StorePointer(InstanceAddr(index), value.raw()); | 2898 StorePointer(InstanceAddr(index), value.raw()); |
| 2881 } | 2899 } |
| 2882 | 2900 |
| 2883 } // namespace dart | 2901 } // namespace dart |
| 2884 | 2902 |
| 2885 #endif // VM_OBJECT_H_ | 2903 #endif // VM_OBJECT_H_ |
| OLD | NEW |