| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 const int initial_size = (isolate == Dart::vm_isolate()) ? | 53 const int initial_size = (isolate == Dart::vm_isolate()) ? |
| 54 kInitialVMIsolateSymtabSize : kInitialSymtabSize; | 54 kInitialVMIsolateSymtabSize : kInitialSymtabSize; |
| 55 const Array& array = Array::Handle(Array::New(initial_size + 1)); | 55 const Array& array = Array::Handle(Array::New(initial_size + 1)); |
| 56 | 56 |
| 57 // Last element contains the count of used slots. | 57 // Last element contains the count of used slots. |
| 58 array.SetAt(initial_size, Smi::Handle(Smi::New(0))); | 58 array.SetAt(initial_size, Smi::Handle(Smi::New(0))); |
| 59 isolate->object_store()->set_symbol_table(array); | 59 isolate->object_store()->set_symbol_table(array); |
| 60 } | 60 } |
| 61 | 61 |
| 62 | 62 |
| 63 intptr_t Symbols::Size(Isolate* isolate) { |
| 64 ASSERT(isolate != NULL); |
| 65 Array& symbol_table = Array::Handle(isolate, |
| 66 isolate->object_store()->symbol_table()); |
| 67 intptr_t table_size_index = symbol_table.Length() - 1; |
| 68 Smi& used = Smi::Handle(); |
| 69 used ^= symbol_table.At(table_size_index); |
| 70 return used.Value(); |
| 71 } |
| 72 |
| 73 |
| 63 void Symbols::Add(const Array& symbol_table, const String& str) { | 74 void Symbols::Add(const Array& symbol_table, const String& str) { |
| 64 // Should only be run by the vm isolate. | 75 // Should only be run by the vm isolate. |
| 65 ASSERT(Isolate::Current() == Dart::vm_isolate()); | 76 ASSERT(Isolate::Current() == Dart::vm_isolate()); |
| 66 intptr_t hash = str.Hash(); | 77 intptr_t hash = str.Hash(); |
| 67 intptr_t index = FindIndex(symbol_table, str, 0, str.Length(), hash); | 78 intptr_t index = FindIndex(symbol_table, str, 0, str.Length(), hash); |
| 68 ASSERT(symbol_table.At(index) == String::null()); | 79 ASSERT(symbol_table.At(index) == String::null()); |
| 69 InsertIntoSymbolTable(symbol_table, str, index); | 80 InsertIntoSymbolTable(symbol_table, str, index); |
| 70 } | 81 } |
| 71 | 82 |
| 72 | 83 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 String& symbol = String::Handle(); | 284 String& symbol = String::Handle(); |
| 274 symbol ^= symbol_table.At(index); | 285 symbol ^= symbol_table.At(index); |
| 275 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) { | 286 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) { |
| 276 index = (index + 1) % table_size; // Move to next element. | 287 index = (index + 1) % table_size; // Move to next element. |
| 277 symbol ^= symbol_table.At(index); | 288 symbol ^= symbol_table.At(index); |
| 278 } | 289 } |
| 279 return index; // Index of symbol if found or slot into which to add symbol. | 290 return index; // Index of symbol if found or slot into which to add symbol. |
| 280 } | 291 } |
| 281 | 292 |
| 282 } // namespace dart | 293 } // namespace dart |
| OLD | NEW |