| 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 (uint32_t c = 0; c <= kMaxOneCharCodeSymbol; c++) { | 58 for (int32_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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 template RawString* Symbols::New(const int32_t* characters, intptr_t len); |
| 156 | 156 |
| 157 | 157 |
| 158 RawString* Symbols::New(const String& str) { | 158 RawString* Symbols::New(const String& str) { |
| 159 if (str.IsSymbol()) { | 159 if (str.IsSymbol()) { |
| 160 return str.raw(); | 160 return str.raw(); |
| 161 } | 161 } |
| 162 return New(str, 0, str.Length()); | 162 return New(str, 0, str.Length()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 | 165 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 symbol.SetHash(hash); | 197 symbol.SetHash(hash); |
| 198 } | 198 } |
| 199 InsertIntoSymbolTable(symbol_table, symbol, index); | 199 InsertIntoSymbolTable(symbol_table, symbol, index); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 ASSERT(symbol.IsSymbol()); | 202 ASSERT(symbol.IsSymbol()); |
| 203 return symbol.raw(); | 203 return symbol.raw(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 | 206 |
| 207 RawString* Symbols::FromCharCode(uint32_t char_code) { | 207 RawString* Symbols::FromCharCode(int32_t char_code) { |
| 208 if (char_code > kMaxOneCharCodeSymbol) { | 208 if (char_code > kMaxOneCharCodeSymbol) { |
| 209 return New(&char_code, 1); | 209 return New(&char_code, 1); |
| 210 } | 210 } |
| 211 return predefined_[kNullCharId + char_code]; | 211 return predefined_[kNullCharId + char_code]; |
| 212 } | 212 } |
| 213 | 213 |
| 214 | 214 |
| 215 void Symbols::GrowSymbolTable(const Array& symbol_table) { | 215 void Symbols::GrowSymbolTable(const Array& symbol_table) { |
| 216 // TODO(iposva): Avoid exponential growth. | 216 // TODO(iposva): Avoid exponential growth. |
| 217 intptr_t table_size = symbol_table.Length() - 1; | 217 intptr_t table_size = symbol_table.Length() - 1; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 282 |
| 283 template intptr_t Symbols::FindIndex(const Array& symbol_table, | 283 template intptr_t Symbols::FindIndex(const Array& symbol_table, |
| 284 const uint8_t* characters, | 284 const uint8_t* characters, |
| 285 intptr_t len, | 285 intptr_t len, |
| 286 intptr_t hash); | 286 intptr_t hash); |
| 287 template intptr_t Symbols::FindIndex(const Array& symbol_table, | 287 template intptr_t Symbols::FindIndex(const Array& symbol_table, |
| 288 const uint16_t* characters, | 288 const uint16_t* characters, |
| 289 intptr_t len, | 289 intptr_t len, |
| 290 intptr_t hash); | 290 intptr_t hash); |
| 291 template intptr_t Symbols::FindIndex(const Array& symbol_table, | 291 template intptr_t Symbols::FindIndex(const Array& symbol_table, |
| 292 const uint32_t* characters, | 292 const int32_t* characters, |
| 293 intptr_t len, | 293 intptr_t len, |
| 294 intptr_t hash); | 294 intptr_t hash); |
| 295 | 295 |
| 296 | 296 |
| 297 intptr_t Symbols::FindIndex(const Array& symbol_table, | 297 intptr_t Symbols::FindIndex(const Array& symbol_table, |
| 298 const String& str, | 298 const String& str, |
| 299 intptr_t begin_index, | 299 intptr_t begin_index, |
| 300 intptr_t len, | 300 intptr_t len, |
| 301 intptr_t hash) { | 301 intptr_t hash) { |
| 302 // Last element of the array is the number of used elements. | 302 // Last element of the array is the number of used elements. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 323 } | 323 } |
| 324 | 324 |
| 325 | 325 |
| 326 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { | 326 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { |
| 327 ASSERT(IsVMSymbolId(object_id)); | 327 ASSERT(IsVMSymbolId(object_id)); |
| 328 intptr_t i = (object_id - kMaxPredefinedObjectIds); | 328 intptr_t i = (object_id - kMaxPredefinedObjectIds); |
| 329 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); | 329 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); |
| 330 } | 330 } |
| 331 | 331 |
| 332 } // namespace dart | 332 } // namespace dart |
| OLD | NEW |