OLD | NEW |
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 #include "vm/symbols.h" | 5 #include "vm/symbols.h" |
6 | 6 |
7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
8 #include "vm/object.h" | 8 #include "vm/object.h" |
9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
10 #include "vm/raw_object.h" | 10 #include "vm/raw_object.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 for (intptr_t i = 1; i < Symbols::kMaxPredefinedId; i++) { | 48 for (intptr_t i = 1; i < Symbols::kMaxPredefinedId; i++) { |
49 // The symbol_table needs to be reloaded as it might have grown in the | 49 // The symbol_table needs to be reloaded as it might have grown in the |
50 // previous iteration. | 50 // previous iteration. |
51 symbol_table = object_store->symbol_table(); | 51 symbol_table = object_store->symbol_table(); |
52 str = OneByteString::New(names[i], Heap::kOld); | 52 str = OneByteString::New(names[i], Heap::kOld); |
53 Add(symbol_table, str); | 53 Add(symbol_table, str); |
54 predefined_[i] = str.raw(); | 54 predefined_[i] = str.raw(); |
55 } | 55 } |
56 Object::RegisterSingletonClassNames(); | 56 Object::RegisterSingletonClassNames(); |
57 | 57 |
58 for (uint16_t c = 0; c <= kMaxOneCharCodeSymbol; c++) { | 58 for (uint32_t c = 0; c <= kMaxOneCharCodeSymbol; c++) { |
59 ASSERT(kMaxPredefinedId + c < kMaxId); | 59 ASSERT(kMaxPredefinedId + c < kMaxId); |
60 predefined_[kMaxPredefinedId + c] = New(&c, 1); | 60 predefined_[kMaxPredefinedId + c] = New(&c, 1); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 | 64 |
65 void Symbols::SetupSymbolTable(Isolate* isolate) { | 65 void Symbols::SetupSymbolTable(Isolate* isolate) { |
66 ASSERT(isolate != NULL); | 66 ASSERT(isolate != NULL); |
67 | 67 |
68 // Setup the symbol table used within the String class. | 68 // Setup the symbol table used within the String class. |
(...skipping 26 matching lines...) Expand all Loading... |
95 ASSERT(symbol_table.At(index) == String::null()); | 95 ASSERT(symbol_table.At(index) == String::null()); |
96 InsertIntoSymbolTable(symbol_table, str, index); | 96 InsertIntoSymbolTable(symbol_table, str, index); |
97 } | 97 } |
98 | 98 |
99 | 99 |
100 RawString* Symbols::New(const char* str) { | 100 RawString* Symbols::New(const char* str) { |
101 ASSERT(str != NULL); | 101 ASSERT(str != NULL); |
102 Utf8::Type type; | 102 Utf8::Type type; |
103 intptr_t str_len = strlen(str); | 103 intptr_t str_len = strlen(str); |
104 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str); | 104 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str); |
105 intptr_t len = Utf8::CodeUnitCount(utf8_array, str_len, &type); | 105 intptr_t len = Utf8::CodePointCount(utf8_array, str_len, &type); |
106 Zone* zone = Isolate::Current()->current_zone(); | 106 Zone* zone = Isolate::Current()->current_zone(); |
107 if (len == 0) { | 107 if (len == 0) { |
108 return Symbols::New(reinterpret_cast<uint8_t*>(NULL), 0); | 108 return Symbols::New(reinterpret_cast<uint8_t*>(NULL), 0); |
109 } | 109 } |
110 if (type == Utf8::kLatin1) { | 110 if (type == Utf8::kLatin1) { |
111 uint8_t* characters = zone->Alloc<uint8_t>(len); | 111 uint8_t* characters = zone->Alloc<uint8_t>(len); |
112 Utf8::DecodeToLatin1(utf8_array, str_len, characters, len); | 112 Utf8::DecodeToLatin1(utf8_array, str_len, characters, len); |
113 return New(characters, len); | 113 return New(characters, len); |
114 } | 114 } |
115 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSupplementary)); | 115 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSupplementary)); |
(...skipping 29 matching lines...) Expand all Loading... |
145 symbol.SetHash(hash); // Remember the calculated hash value. | 145 symbol.SetHash(hash); // Remember the calculated hash value. |
146 InsertIntoSymbolTable(symbol_table, symbol, index); | 146 InsertIntoSymbolTable(symbol_table, symbol, index); |
147 } | 147 } |
148 } | 148 } |
149 ASSERT(symbol.IsSymbol()); | 149 ASSERT(symbol.IsSymbol()); |
150 return symbol.raw(); | 150 return symbol.raw(); |
151 } | 151 } |
152 | 152 |
153 template RawString* Symbols::New(const uint8_t* characters, intptr_t len); | 153 template RawString* Symbols::New(const uint8_t* characters, intptr_t len); |
154 template RawString* Symbols::New(const uint16_t* characters, intptr_t len); | 154 template RawString* Symbols::New(const uint16_t* characters, intptr_t len); |
| 155 template RawString* Symbols::New(const uint32_t* characters, intptr_t len); |
155 | 156 |
156 | 157 |
157 RawString* Symbols::New(const String& str) { | 158 RawString* Symbols::New(const String& str) { |
158 if (str.IsSymbol()) { | 159 if (str.IsSymbol()) { |
159 return str.raw(); | 160 return str.raw(); |
160 } | 161 } |
161 return New(str, 0, str.Length()); | 162 return New(str, 0, str.Length()); |
162 } | 163 } |
163 | 164 |
164 | 165 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 symbol.SetHash(hash); | 197 symbol.SetHash(hash); |
197 } | 198 } |
198 InsertIntoSymbolTable(symbol_table, symbol, index); | 199 InsertIntoSymbolTable(symbol_table, symbol, index); |
199 } | 200 } |
200 } | 201 } |
201 ASSERT(symbol.IsSymbol()); | 202 ASSERT(symbol.IsSymbol()); |
202 return symbol.raw(); | 203 return symbol.raw(); |
203 } | 204 } |
204 | 205 |
205 | 206 |
206 RawString* Symbols::FromCharCode(int32_t char_code) { | 207 RawString* Symbols::FromCharCode(uint32_t char_code) { |
207 if (char_code > kMaxOneCharCodeSymbol) { | 208 if (char_code > kMaxOneCharCodeSymbol) { |
208 if (char_code > Utf16::kMaxBmpCodepoint) { | 209 return New(&char_code, 1); |
209 uint16_t code_units[2]; | |
210 Utf16::Encode(char_code, &code_units[0]); | |
211 return New(&code_units[0], 2); | |
212 } else { | |
213 uint16_t code_unit = char_code; | |
214 return New(&code_unit, 1); | |
215 } | |
216 } | 210 } |
217 return predefined_[kNullCharId + char_code]; | 211 return predefined_[kNullCharId + char_code]; |
218 } | 212 } |
219 | 213 |
220 | 214 |
221 void Symbols::GrowSymbolTable(const Array& symbol_table) { | 215 void Symbols::GrowSymbolTable(const Array& symbol_table) { |
222 // TODO(iposva): Avoid exponential growth. | 216 // TODO(iposva): Avoid exponential growth. |
223 intptr_t table_size = symbol_table.Length() - 1; | 217 intptr_t table_size = symbol_table.Length() - 1; |
224 intptr_t new_table_size = table_size * 2; | 218 intptr_t new_table_size = table_size * 2; |
225 Array& new_symbol_table = Array::Handle(Array::New(new_table_size + 1)); | 219 Array& new_symbol_table = Array::Handle(Array::New(new_table_size + 1)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 281 |
288 | 282 |
289 template intptr_t Symbols::FindIndex(const Array& symbol_table, | 283 template intptr_t Symbols::FindIndex(const Array& symbol_table, |
290 const uint8_t* characters, | 284 const uint8_t* characters, |
291 intptr_t len, | 285 intptr_t len, |
292 intptr_t hash); | 286 intptr_t hash); |
293 template intptr_t Symbols::FindIndex(const Array& symbol_table, | 287 template intptr_t Symbols::FindIndex(const Array& symbol_table, |
294 const uint16_t* characters, | 288 const uint16_t* characters, |
295 intptr_t len, | 289 intptr_t len, |
296 intptr_t hash); | 290 intptr_t hash); |
| 291 template intptr_t Symbols::FindIndex(const Array& symbol_table, |
| 292 const uint32_t* characters, |
| 293 intptr_t len, |
| 294 intptr_t hash); |
| 295 |
297 | 296 |
298 intptr_t Symbols::FindIndex(const Array& symbol_table, | 297 intptr_t Symbols::FindIndex(const Array& symbol_table, |
299 const String& str, | 298 const String& str, |
300 intptr_t begin_index, | 299 intptr_t begin_index, |
301 intptr_t len, | 300 intptr_t len, |
302 intptr_t hash) { | 301 intptr_t hash) { |
303 // Last element of the array is the number of used elements. | 302 // Last element of the array is the number of used elements. |
304 intptr_t table_size = symbol_table.Length() - 1; | 303 intptr_t table_size = symbol_table.Length() - 1; |
305 intptr_t index = hash % table_size; | 304 intptr_t index = hash % table_size; |
306 | 305 |
(...skipping 17 matching lines...) Expand all Loading... |
324 } | 323 } |
325 | 324 |
326 | 325 |
327 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { | 326 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { |
328 ASSERT(IsVMSymbolId(object_id)); | 327 ASSERT(IsVMSymbolId(object_id)); |
329 intptr_t i = (object_id - kMaxPredefinedObjectIds); | 328 intptr_t i = (object_id - kMaxPredefinedObjectIds); |
330 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); | 329 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); |
331 } | 330 } |
332 | 331 |
333 } // namespace dart | 332 } // namespace dart |
OLD | NEW |