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

Side by Side Diff: runtime/vm/object.h

Issue 11368138: Add some support for the code-point code-unit distinction. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Implemented feedback from patch set 2. Created 8 years, 1 month 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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
11 #include "vm/bitmap.h" 11 #include "vm/bitmap.h"
12 #include "vm/dart.h" 12 #include "vm/dart.h"
13 #include "vm/globals.h" 13 #include "vm/globals.h"
14 #include "vm/handles.h" 14 #include "vm/handles.h"
15 #include "vm/heap.h" 15 #include "vm/heap.h"
16 #include "vm/isolate.h" 16 #include "vm/isolate.h"
17 #include "vm/os.h" 17 #include "vm/os.h"
18 #include "vm/raw_object.h" 18 #include "vm/raw_object.h"
19 #include "vm/scanner.h" 19 #include "vm/scanner.h"
20 #include "vm/unicode.h"
20 21
21 namespace dart { 22 namespace dart {
22 23
23 // Forward declarations. 24 // Forward declarations.
24 #define DEFINE_FORWARD_DECLARATION(clazz) \ 25 #define DEFINE_FORWARD_DECLARATION(clazz) \
25 class clazz; 26 class clazz;
26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) 27 CLASS_LIST(DEFINE_FORWARD_DECLARATION)
27 #undef DEFINE_FORWARD_DECLARATION 28 #undef DEFINE_FORWARD_DECLARATION
28 class Api; 29 class Api;
29 class Assembler; 30 class Assembler;
(...skipping 3679 matching lines...) Expand 10 before | Expand all | Expand 10 after
3709 static const intptr_t kMaxElements = kSmiMax / kTwoByteChar; 3710 static const intptr_t kMaxElements = kSmiMax / kTwoByteChar;
3710 3711
3711 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } 3712 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); }
3712 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } 3713 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); }
3713 3714
3714 virtual intptr_t Hash() const; 3715 virtual intptr_t Hash() const;
3715 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } 3716 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); }
3716 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); 3717 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len);
3717 static intptr_t Hash(const uint8_t* characters, intptr_t len); 3718 static intptr_t Hash(const uint8_t* characters, intptr_t len);
3718 static intptr_t Hash(const uint16_t* characters, intptr_t len); 3719 static intptr_t Hash(const uint16_t* characters, intptr_t len);
3719 static intptr_t Hash(const uint32_t* characters, intptr_t len); 3720 static intptr_t Hash(const int32_t* characters, intptr_t len);
3720 3721
3722 // Despite the name, this does not return the character. It returns the
3723 // UTF-16 code unit at an index. UTF-16 is a superset of ASCII so you can
3724 // always use this if you are looking for ASCII. If you need to support
siva 2012/11/16 22:32:04 Should we say ASCII or Latin1 here?
erikcorry 2012/11/19 12:40:41 Now says both.
3725 // arbitrary Unicode characters then you should perhaps be using
3726 // Utf16::CharCodeAt(string, index), which returns the full 21 bit code point.
3721 int32_t CharAt(intptr_t index) const; 3727 int32_t CharAt(intptr_t index) const;
3722 3728
3723 intptr_t CharSize() const; 3729 intptr_t CharSize() const;
3724 3730
3725 inline bool Equals(const String& str) const; 3731 inline bool Equals(const String& str) const;
3726 inline bool Equals(const String& str, 3732 inline bool Equals(const String& str,
3727 intptr_t begin_index, // begin index on 'str'. 3733 intptr_t begin_index, // begin index on 'str'.
3728 intptr_t len) const; // len on 'str'. 3734 intptr_t len) const; // len on 'str'.
3729 bool Equals(const char* str) const; 3735 bool Equals(const char* str) const;
3730 bool Equals(const uint8_t* characters, intptr_t len) const; 3736 bool Equals(const uint8_t* characters, intptr_t len) const;
3731 bool Equals(const uint16_t* characters, intptr_t len) const; 3737 bool Equals(const uint16_t* characters, intptr_t len) const;
3732 bool Equals(const uint32_t* characters, intptr_t len) const; 3738 bool Equals(const int32_t* characters, intptr_t len) const;
3733 3739
3734 virtual bool Equals(const Instance& other) const; 3740 virtual bool Equals(const Instance& other) const;
3735 3741
3736 intptr_t CompareTo(const String& other) const; 3742 intptr_t CompareTo(const String& other) const;
3737 3743
3738 bool StartsWith(const String& other) const; 3744 bool StartsWith(const String& other) const;
3739 3745
3740 virtual RawInstance* Canonicalize() const; 3746 virtual RawInstance* Canonicalize() const;
3741 3747
3742 bool IsSymbol() const { return raw()->IsCanonical(); } 3748 bool IsSymbol() const { return raw()->IsCanonical(); }
(...skipping 30 matching lines...) Expand all
3773 static RawString* New(const uint8_t* utf8_array, 3779 static RawString* New(const uint8_t* utf8_array,
3774 intptr_t array_len, 3780 intptr_t array_len,
3775 Heap::Space space = Heap::kNew); 3781 Heap::Space space = Heap::kNew);
3776 3782
3777 // Creates a new String object from an array of UTF-16 encoded characters. 3783 // Creates a new String object from an array of UTF-16 encoded characters.
3778 static RawString* New(const uint16_t* utf16_array, 3784 static RawString* New(const uint16_t* utf16_array,
3779 intptr_t array_len, 3785 intptr_t array_len,
3780 Heap::Space space = Heap::kNew); 3786 Heap::Space space = Heap::kNew);
3781 3787
3782 // Creates a new String object from an array of UTF-32 encoded characters. 3788 // Creates a new String object from an array of UTF-32 encoded characters.
3783 static RawString* New(const uint32_t* utf32_array, 3789 static RawString* New(const int32_t* utf32_array,
3784 intptr_t array_len, 3790 intptr_t array_len,
3785 Heap::Space space = Heap::kNew); 3791 Heap::Space space = Heap::kNew);
3786 3792
3787 // Create a new String object from another Dart String instance. 3793 // Create a new String object from another Dart String instance.
3788 static RawString* New(const String& str, Heap::Space space = Heap::kNew); 3794 static RawString* New(const String& str, Heap::Space space = Heap::kNew);
3789 3795
3790 // Creates a new External String object using the specified array of 3796 // Creates a new External String object using the specified array of
3791 // UTF-8 encoded characters as the external reference. 3797 // UTF-8 encoded characters as the external reference.
3792 static RawString* NewExternal(const uint8_t* utf8_array, 3798 static RawString* NewExternal(const uint8_t* utf8_array,
3793 intptr_t array_len, 3799 intptr_t array_len,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
3919 return New(reinterpret_cast<const uint8_t*>(c_string), 3925 return New(reinterpret_cast<const uint8_t*>(c_string),
3920 strlen(c_string), 3926 strlen(c_string),
3921 space); 3927 space);
3922 } 3928 }
3923 static RawOneByteString* New(const uint8_t* characters, 3929 static RawOneByteString* New(const uint8_t* characters,
3924 intptr_t len, 3930 intptr_t len,
3925 Heap::Space space); 3931 Heap::Space space);
3926 static RawOneByteString* New(const uint16_t* characters, 3932 static RawOneByteString* New(const uint16_t* characters,
3927 intptr_t len, 3933 intptr_t len,
3928 Heap::Space space); 3934 Heap::Space space);
3929 static RawOneByteString* New(const uint32_t* characters, 3935 static RawOneByteString* New(const int32_t* characters,
3930 intptr_t len, 3936 intptr_t len,
3931 Heap::Space space); 3937 Heap::Space space);
3932 static RawOneByteString* New(const String& str, 3938 static RawOneByteString* New(const String& str,
3933 Heap::Space space); 3939 Heap::Space space);
3934 3940
3935 static RawOneByteString* Concat(const String& str1, 3941 static RawOneByteString* Concat(const String& str1,
3936 const String& str2, 3942 const String& str2,
3937 Heap::Space space); 3943 Heap::Space space);
3938 static RawOneByteString* ConcatAll(const Array& strings, 3944 static RawOneByteString* ConcatAll(const Array& strings,
3939 intptr_t len, 3945 intptr_t len,
3940 Heap::Space space); 3946 Heap::Space space);
3941 3947
3942 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch), 3948 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch),
3943 const String& str, 3949 const String& str,
3950 int out_length,
siva 2012/11/16 22:32:04 we always use intptr_t for length values in the VM
erikcorry 2012/11/19 12:40:41 Done.
3944 Heap::Space space); 3951 Heap::Space space);
3945 3952
3946 static const ClassId kClassId = kOneByteStringCid; 3953 static const ClassId kClassId = kOneByteStringCid;
3947 3954
3948 static RawOneByteString* null() { 3955 static RawOneByteString* null() {
3949 return reinterpret_cast<RawOneByteString*>(Object::null()); 3956 return reinterpret_cast<RawOneByteString*>(Object::null());
3950 } 3957 }
3951 3958
3952 private: 3959 private:
3953 static RawOneByteString* raw(const String& str) { 3960 static RawOneByteString* raw(const String& str) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
4002 return String::RoundedAllocationSize( 4009 return String::RoundedAllocationSize(
4003 sizeof(RawTwoByteString) + (len * kBytesPerElement)); 4010 sizeof(RawTwoByteString) + (len * kBytesPerElement));
4004 } 4011 }
4005 4012
4006 static RawTwoByteString* New(intptr_t len, 4013 static RawTwoByteString* New(intptr_t len,
4007 Heap::Space space); 4014 Heap::Space space);
4008 static RawTwoByteString* New(const uint16_t* characters, 4015 static RawTwoByteString* New(const uint16_t* characters,
4009 intptr_t len, 4016 intptr_t len,
4010 Heap::Space space); 4017 Heap::Space space);
4011 static RawTwoByteString* New(intptr_t utf16_len, 4018 static RawTwoByteString* New(intptr_t utf16_len,
4012 const uint32_t* characters, 4019 const int32_t* characters,
4013 intptr_t len, 4020 intptr_t len,
4014 Heap::Space space); 4021 Heap::Space space);
4015 static RawTwoByteString* New(const String& str, 4022 static RawTwoByteString* New(const String& str,
4016 Heap::Space space); 4023 Heap::Space space);
4017 4024
4018 static RawTwoByteString* Concat(const String& str1, 4025 static RawTwoByteString* Concat(const String& str1,
4019 const String& str2, 4026 const String& str2,
4020 Heap::Space space); 4027 Heap::Space space);
4021 static RawTwoByteString* ConcatAll(const Array& strings, 4028 static RawTwoByteString* ConcatAll(const Array& strings,
4022 intptr_t len, 4029 intptr_t len,
4023 Heap::Space space); 4030 Heap::Space space);
4024 4031
4025 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch), 4032 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch),
4026 const String& str, 4033 const String& str,
4034 int out_length,
siva 2012/11/16 22:32:04 Ditto.
erikcorry 2012/11/19 12:40:41 Done.
4027 Heap::Space space); 4035 Heap::Space space);
4028 4036
4029 static RawTwoByteString* null() { 4037 static RawTwoByteString* null() {
4030 return reinterpret_cast<RawTwoByteString*>(Object::null()); 4038 return reinterpret_cast<RawTwoByteString*>(Object::null());
4031 } 4039 }
4032 4040
4033 4041
4034 static const ClassId kClassId = kTwoByteStringCid; 4042 static const ClassId kClassId = kTwoByteStringCid;
4035 4043
4036 private: 4044 private:
(...skipping 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after
5907 if (this->CharAt(i) != str.CharAt(begin_index + i)) { 5915 if (this->CharAt(i) != str.CharAt(begin_index + i)) {
5908 return false; 5916 return false;
5909 } 5917 }
5910 } 5918 }
5911 return true; 5919 return true;
5912 } 5920 }
5913 5921
5914 } // namespace dart 5922 } // namespace dart
5915 5923
5916 #endif // VM_OBJECT_H_ 5924 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698