Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: runtime/vm/symbols.cc

Issue 428273002: Handle-like interface for HashTable. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/handles.h" 7 #include "vm/handles.h"
8 #include "vm/handles_impl.h" 8 #include "vm/handles_impl.h"
9 #include "vm/hash_table.h" 9 #include "vm/hash_table.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 const intptr_t initial_size = (isolate == Dart::vm_isolate()) ? 210 const intptr_t initial_size = (isolate == Dart::vm_isolate()) ?
211 kInitialVMIsolateSymtabSize : kInitialSymtabSize; 211 kInitialVMIsolateSymtabSize : kInitialSymtabSize;
212 Array& array = 212 Array& array =
213 Array::Handle(HashTables::New<SymbolTable>(initial_size, Heap::kOld)); 213 Array::Handle(HashTables::New<SymbolTable>(initial_size, Heap::kOld));
214 isolate->object_store()->set_symbol_table(array); 214 isolate->object_store()->set_symbol_table(array);
215 } 215 }
216 216
217 217
218 void Symbols::GetStats(Isolate* isolate, intptr_t* size, intptr_t* capacity) { 218 void Symbols::GetStats(Isolate* isolate, intptr_t* size, intptr_t* capacity) {
219 ASSERT(isolate != NULL); 219 ASSERT(isolate != NULL);
220 SymbolTable table(Array::Handle(isolate->object_store()->symbol_table())); 220 SymbolTable table(isolate, isolate->object_store()->symbol_table());
221 *size = table.NumOccupied(); 221 *size = table.NumOccupied();
222 *capacity = table.NumEntries(); 222 *capacity = table.NumEntries();
223 table.Release(); 223 table.Release();
224 } 224 }
225 225
226 226
227 void Symbols::AddToVMIsolate(const String& str) { 227 void Symbols::AddToVMIsolate(const String& str) {
228 // Should only be run by the vm isolate. 228 // Should only be run by the vm isolate.
229 ASSERT(Isolate::Current() == Dart::vm_isolate()); 229 ASSERT(Isolate::Current() == Dart::vm_isolate());
230 Isolate* isolate = Dart::vm_isolate(); 230 Isolate* isolate = Dart::vm_isolate();
231 Array& array = Array::Handle(isolate->object_store()->symbol_table()); 231 SymbolTable table(isolate, isolate->object_store()->symbol_table());
232 SymbolTable table(array);
233 bool present = table.Insert(str); 232 bool present = table.Insert(str);
234 str.SetCanonical(); 233 str.SetCanonical();
235 ASSERT(!present); 234 ASSERT(!present);
236 isolate->object_store()->set_symbol_table(array); 235 isolate->object_store()->set_symbol_table(table.Release());
237 table.Release();
238 } 236 }
239 237
240 238
241 RawString* Symbols::New(const char* cstr, intptr_t len) { 239 RawString* Symbols::New(const char* cstr, intptr_t len) {
242 ASSERT((cstr != NULL) && (len >= 0)); 240 ASSERT((cstr != NULL) && (len >= 0));
243 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(cstr); 241 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(cstr);
244 return Symbols::FromUTF8(utf8_array, len); 242 return Symbols::FromUTF8(utf8_array, len);
245 } 243 }
246 244
247 245
(...skipping 28 matching lines...) Expand all
276 274
277 275
278 RawString* Symbols::FromUTF32(const int32_t* utf32_array, intptr_t len) { 276 RawString* Symbols::FromUTF32(const int32_t* utf32_array, intptr_t len) {
279 return NewSymbol(UTF32Array(utf32_array, len)); 277 return NewSymbol(UTF32Array(utf32_array, len));
280 } 278 }
281 279
282 280
283 // StringType can be StringSlice, Latin1Array, UTF16Array or UTF32Array. 281 // StringType can be StringSlice, Latin1Array, UTF16Array or UTF32Array.
284 template<typename StringType> 282 template<typename StringType>
285 RawString* Symbols::NewSymbol(const StringType& str) { 283 RawString* Symbols::NewSymbol(const StringType& str) {
286 String& symbol = String::Handle(); 284 Isolate* isolate = Isolate::Current();
285 String& symbol = String::Handle(isolate);
287 { 286 {
288 Isolate* isolate = Dart::vm_isolate(); 287 Isolate* vm_isolate = Dart::vm_isolate();
289 Array& array = Array::Handle(isolate->object_store()->symbol_table()); 288 SymbolTable table(isolate, vm_isolate->object_store()->symbol_table());
290 SymbolTable table(array);
291 symbol ^= table.GetOrNull(str); 289 symbol ^= table.GetOrNull(str);
292 table.Release(); 290 table.Release();
293 } 291 }
294 if (symbol.IsNull()) { 292 if (symbol.IsNull()) {
295 Isolate* isolate = Isolate::Current(); 293 SymbolTable table(isolate, isolate->object_store()->symbol_table());
296 Array& array = Array::Handle(isolate->object_store()->symbol_table());
297 SymbolTable table(array);
298 symbol ^= table.InsertNewOrGet(str); 294 symbol ^= table.InsertNewOrGet(str);
299 isolate->object_store()->set_symbol_table(array); 295 isolate->object_store()->set_symbol_table(table.Release());
300 table.Release();
301 } 296 }
302 ASSERT(symbol.IsSymbol()); 297 ASSERT(symbol.IsSymbol());
303 return symbol.raw(); 298 return symbol.raw();
304 } 299 }
305 300
306 301
307 RawString* Symbols::New(const String& str) { 302 RawString* Symbols::New(const String& str) {
308 if (str.IsSymbol()) { 303 if (str.IsSymbol()) {
309 return str.raw(); 304 return str.raw();
310 } 305 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { 351 RawObject* Symbols::GetVMSymbol(intptr_t object_id) {
357 ASSERT(IsVMSymbolId(object_id)); 352 ASSERT(IsVMSymbolId(object_id));
358 intptr_t i = (object_id - kMaxPredefinedObjectIds); 353 intptr_t i = (object_id - kMaxPredefinedObjectIds);
359 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) { 354 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) {
360 return symbol_handles_[i]->raw(); 355 return symbol_handles_[i]->raw();
361 } 356 }
362 return Object::null(); 357 return Object::null();
363 } 358 }
364 359
365 } // namespace dart 360 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698