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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 ASSERT(symbol_table.At(index) == String::null()); | 90 ASSERT(symbol_table.At(index) == String::null()); |
91 InsertIntoSymbolTable(symbol_table, str, index); | 91 InsertIntoSymbolTable(symbol_table, str, index); |
92 } | 92 } |
93 | 93 |
94 | 94 |
95 RawString* Symbols::New(const char* str) { | 95 RawString* Symbols::New(const char* str) { |
96 ASSERT(str != NULL); | 96 ASSERT(str != NULL); |
97 Utf8::Type type; | 97 Utf8::Type type; |
98 intptr_t str_len = strlen(str); | 98 intptr_t str_len = strlen(str); |
99 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str); | 99 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str); |
100 intptr_t len = Utf8::CodePointCount(utf8_array, str_len, &type); | 100 intptr_t len = Utf8::CodeUnitCount(utf8_array, str_len, &type); |
101 Zone* zone = Isolate::Current()->current_zone(); | 101 Zone* zone = Isolate::Current()->current_zone(); |
102 if (len == 0) { | 102 if (len == 0) { |
103 return Symbols::New(reinterpret_cast<uint8_t*>(NULL), 0); | 103 return Symbols::New(reinterpret_cast<uint8_t*>(NULL), 0); |
104 } | 104 } |
105 if (type == Utf8::kAscii) { | 105 if (type == Utf8::kAscii) { |
106 uint8_t* characters = zone->Alloc<uint8_t>(len); | 106 uint8_t* characters = zone->Alloc<uint8_t>(len); |
107 Utf8::DecodeToAscii(utf8_array, str_len, characters, len); | 107 Utf8::DecodeToAscii(utf8_array, str_len, characters, len); |
108 return New(characters, len); | 108 return New(characters, len); |
109 } | 109 } |
110 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP)); | 110 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP)); |
(...skipping 30 matching lines...) Expand all Loading... |
141 symbol.SetHash(hash); // Remember the calculated hash value. | 141 symbol.SetHash(hash); // Remember the calculated hash value. |
142 InsertIntoSymbolTable(symbol_table, symbol, index); | 142 InsertIntoSymbolTable(symbol_table, symbol, index); |
143 } | 143 } |
144 } | 144 } |
145 ASSERT(symbol.IsSymbol()); | 145 ASSERT(symbol.IsSymbol()); |
146 return symbol.raw(); | 146 return symbol.raw(); |
147 } | 147 } |
148 | 148 |
149 template RawString* Symbols::New(const uint8_t* characters, intptr_t len); | 149 template RawString* Symbols::New(const uint8_t* characters, intptr_t len); |
150 template RawString* Symbols::New(const uint16_t* characters, intptr_t len); | 150 template RawString* Symbols::New(const uint16_t* characters, intptr_t len); |
151 template RawString* Symbols::New(const uint32_t* characters, intptr_t len); | 151 template RawString* Symbols::New(const int32_t* characters, intptr_t len); |
152 | 152 |
153 | 153 |
154 RawString* Symbols::New(const String& str) { | 154 RawString* Symbols::New(const String& str) { |
155 if (str.IsSymbol()) { | 155 if (str.IsSymbol()) { |
156 return str.raw(); | 156 return str.raw(); |
157 } | 157 } |
158 return New(str, 0, str.Length()); | 158 return New(str, 0, str.Length()); |
159 } | 159 } |
160 | 160 |
161 | 161 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 270 |
271 template intptr_t Symbols::FindIndex(const Array& symbol_table, | 271 template intptr_t Symbols::FindIndex(const Array& symbol_table, |
272 const uint8_t* characters, | 272 const uint8_t* characters, |
273 intptr_t len, | 273 intptr_t len, |
274 intptr_t hash); | 274 intptr_t hash); |
275 template intptr_t Symbols::FindIndex(const Array& symbol_table, | 275 template intptr_t Symbols::FindIndex(const Array& symbol_table, |
276 const uint16_t* characters, | 276 const uint16_t* characters, |
277 intptr_t len, | 277 intptr_t len, |
278 intptr_t hash); | 278 intptr_t hash); |
279 template intptr_t Symbols::FindIndex(const Array& symbol_table, | 279 template intptr_t Symbols::FindIndex(const Array& symbol_table, |
280 const uint32_t* characters, | 280 const int32_t* characters, |
281 intptr_t len, | 281 intptr_t len, |
282 intptr_t hash); | 282 intptr_t hash); |
283 | 283 |
284 | 284 |
285 intptr_t Symbols::FindIndex(const Array& symbol_table, | 285 intptr_t Symbols::FindIndex(const Array& symbol_table, |
286 const String& str, | 286 const String& str, |
287 intptr_t begin_index, | 287 intptr_t begin_index, |
288 intptr_t len, | 288 intptr_t len, |
289 intptr_t hash) { | 289 intptr_t hash) { |
290 // Last element of the array is the number of used elements. | 290 // Last element of the array is the number of used elements. |
(...skipping 20 matching lines...) Expand all Loading... |
311 } | 311 } |
312 | 312 |
313 | 313 |
314 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { | 314 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { |
315 ASSERT(IsVMSymbolId(object_id)); | 315 ASSERT(IsVMSymbolId(object_id)); |
316 intptr_t i = (object_id - kMaxPredefinedObjectIds); | 316 intptr_t i = (object_id - kMaxPredefinedObjectIds); |
317 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); | 317 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); |
318 } | 318 } |
319 | 319 |
320 } // namespace dart | 320 } // namespace dart |
OLD | NEW |