| 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" |
| 11 #include "vm/unicode.h" | 11 #include "vm/unicode.h" |
| 12 #include "vm/visitor.h" | 12 #include "vm/visitor.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 RawString* Symbols::predefined_[Symbols::kMaxPredefined]; | 16 RawString* Symbols::predefined_[Symbols::kMaxPredefined]; |
| 17 | 17 |
| 18 #if 0 |
| 18 static const char* names[] = { | 19 static const char* names[] = { |
| 19 NULL, | 20 NULL, |
| 20 | 21 |
| 21 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ | 22 #define DEFINE_SYMBOL_LITERAL(symbol, literal) \ |
| 22 literal, | 23 literal, |
| 23 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL) | 24 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL) |
| 24 #undef DEFINE_SYMBOL_LITERAL | 25 #undef DEFINE_SYMBOL_LITERAL |
| 25 }; | 26 }; |
| 27 #endif |
| 26 | 28 |
| 27 | 29 |
| 28 void Symbols::InitOnce(Isolate* isolate) { | 30 void Symbols::InitOnce(Isolate* isolate) { |
| 29 // Should only be run by the vm isolate. | 31 // Should only be run by the vm isolate. |
| 30 ASSERT(isolate == Dart::vm_isolate()); | 32 ASSERT(isolate == Dart::vm_isolate()); |
| 31 | 33 |
| 32 // Create and setup a symbol table in the vm isolate. | 34 // Create and setup a symbol table in the vm isolate. |
| 33 SetupSymbolTable(isolate); | 35 SetupSymbolTable(isolate); |
| 34 | 36 |
| 37 #if 0 |
| 35 // Create all predefined symbols. | 38 // Create all predefined symbols. |
| 36 ASSERT((sizeof(names) / sizeof(const char*)) == kMaxPredefined); | 39 ASSERT((sizeof(names) / sizeof(const char*)) == kMaxPredefined); |
| 37 const Array& symbol_table = | 40 const Array& symbol_table = |
| 38 Array::Handle(isolate->object_store()->symbol_table()); | 41 Array::Handle(isolate->object_store()->symbol_table()); |
| 39 OneByteString& str = OneByteString::Handle(); | 42 OneByteString& str = OneByteString::Handle(); |
| 40 | 43 |
| 41 for (intptr_t i = 1; i < kMaxPredefined; i++) { | 44 for (intptr_t i = 1; i < kMaxPredefined; i++) { |
| 42 str = OneByteString::New(names[i], Heap::kOld); | 45 str = OneByteString::New(names[i], Heap::kOld); |
| 43 Add(symbol_table, str); | 46 Add(symbol_table, str); |
| 44 predefined_[i] = str.raw(); | 47 predefined_[i] = str.raw(); |
| 45 } | 48 } |
| 49 #endif |
| 46 } | 50 } |
| 47 | 51 |
| 48 | 52 |
| 49 void Symbols::SetupSymbolTable(Isolate* isolate) { | 53 void Symbols::SetupSymbolTable(Isolate* isolate) { |
| 50 ASSERT(isolate != NULL); | 54 ASSERT(isolate != NULL); |
| 51 | 55 |
| 52 // Setup the symbol table used within the String class. | 56 // Setup the symbol table used within the String class. |
| 53 const int initial_size = (isolate == Dart::vm_isolate()) ? | 57 const int initial_size = (isolate == Dart::vm_isolate()) ? |
| 54 kInitialVMIsolateSymtabSize : kInitialSymtabSize; | 58 kInitialVMIsolateSymtabSize : kInitialSymtabSize; |
| 55 const Array& array = Array::Handle(Array::New(initial_size + 1)); | 59 const Array& array = Array::Handle(Array::New(initial_size + 1)); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 String& symbol = String::Handle(); | 288 String& symbol = String::Handle(); |
| 285 symbol ^= symbol_table.At(index); | 289 symbol ^= symbol_table.At(index); |
| 286 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) { | 290 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) { |
| 287 index = (index + 1) % table_size; // Move to next element. | 291 index = (index + 1) % table_size; // Move to next element. |
| 288 symbol ^= symbol_table.At(index); | 292 symbol ^= symbol_table.At(index); |
| 289 } | 293 } |
| 290 return index; // Index of symbol if found or slot into which to add symbol. | 294 return index; // Index of symbol if found or slot into which to add symbol. |
| 291 } | 295 } |
| 292 | 296 |
| 293 } // namespace dart | 297 } // namespace dart |
| OLD | NEW |