Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 // Setup the symbol table used within the String class. | 41 // Setup the symbol table used within the String class. |
| 42 const Array& array = Array::Handle(Array::New(kInitialSymbolTableSize + 1)); | 42 const Array& array = Array::Handle(Array::New(kInitialSymbolTableSize + 1)); |
| 43 | 43 |
| 44 // Last element contains the count of used slots. | 44 // Last element contains the count of used slots. |
| 45 array.SetAt(kInitialSymbolTableSize, Smi::Handle(Smi::New(0))); | 45 array.SetAt(kInitialSymbolTableSize, Smi::Handle(Smi::New(0))); |
| 46 isolate->object_store()->set_symbol_table(array); | 46 isolate->object_store()->set_symbol_table(array); |
| 47 } | 47 } |
| 48 | 48 |
| 49 | 49 |
| 50 intptr_t Symbols::UsedCount(Isolate* isolate) { | |
|
cshapiro
2012/07/25 02:57:20
Naming this method Size and renaming the variable
siva
2012/07/25 23:41:15
I called the method 'Size' as it is a count of ent
| |
| 51 ASSERT(isolate != NULL); | |
| 52 Array& symbol_table = Array::Handle(isolate, | |
| 53 isolate->object_store()->symbol_table()); | |
| 54 intptr_t table_size = symbol_table.Length() - 1; | |
| 55 Smi& used = Smi::Handle(); | |
| 56 used ^= symbol_table.At(table_size); | |
| 57 return used.Value(); | |
| 58 } | |
| 59 | |
| 60 | |
| 50 void Symbols::Add(const Array& symbol_table, const String& str) { | 61 void Symbols::Add(const Array& symbol_table, const String& str) { |
| 51 // Should only be run by the vm isolate. | 62 // Should only be run by the vm isolate. |
| 52 ASSERT(Isolate::Current() == Dart::vm_isolate()); | 63 ASSERT(Isolate::Current() == Dart::vm_isolate()); |
| 53 intptr_t hash = str.Hash(); | 64 intptr_t hash = str.Hash(); |
| 54 intptr_t index = FindIndex(symbol_table, str, 0, str.Length(), hash); | 65 intptr_t index = FindIndex(symbol_table, str, 0, str.Length(), hash); |
| 55 ASSERT(symbol_table.At(index) == String::null()); | 66 ASSERT(symbol_table.At(index) == String::null()); |
| 56 InsertIntoSymbolTable(symbol_table, str, index); | 67 InsertIntoSymbolTable(symbol_table, str, index); |
| 57 } | 68 } |
| 58 | 69 |
| 59 | 70 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 String& symbol = String::Handle(); | 271 String& symbol = String::Handle(); |
| 261 symbol ^= symbol_table.At(index); | 272 symbol ^= symbol_table.At(index); |
| 262 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) { | 273 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) { |
| 263 index = (index + 1) % table_size; // Move to next element. | 274 index = (index + 1) % table_size; // Move to next element. |
| 264 symbol ^= symbol_table.At(index); | 275 symbol ^= symbol_table.At(index); |
| 265 } | 276 } |
| 266 return index; // Index of symbol if found or slot into which to add symbol. | 277 return index; // Index of symbol if found or slot into which to add symbol. |
| 267 } | 278 } |
| 268 | 279 |
| 269 } // namespace dart | 280 } // namespace dart |
| OLD | NEW |