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

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

Issue 1320673012: Lookup getter/setter symbols before alllocating them, thus eliminating extra String allocations in … (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Formatting Created 5 years, 3 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
« no previous file with comments | « runtime/vm/symbols.h ('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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 SymbolTable table(zone, isolate->object_store()->symbol_table()); 485 SymbolTable table(zone, isolate->object_store()->symbol_table());
486 symbol ^= table.InsertNewOrGet(str); 486 symbol ^= table.InsertNewOrGet(str);
487 isolate->object_store()->set_symbol_table(table.Release()); 487 isolate->object_store()->set_symbol_table(table.Release());
488 } 488 }
489 ASSERT(symbol.IsSymbol()); 489 ASSERT(symbol.IsSymbol());
490 ASSERT(symbol.HasHash()); 490 ASSERT(symbol.HasHash());
491 return symbol.raw(); 491 return symbol.raw();
492 } 492 }
493 493
494 494
495 template<typename StringType>
496 RawString* Symbols::Lookup(const StringType& str) {
497 Thread* thread = Thread::Current();
498 Isolate* isolate = thread->isolate();
499 Zone* zone = thread->zone();
500 String& symbol = String::Handle(zone);
501 {
502 Isolate* vm_isolate = Dart::vm_isolate();
503 SymbolTable table(zone, vm_isolate->object_store()->symbol_table());
504 symbol ^= table.GetOrNull(str);
505 table.Release();
506 }
507 if (symbol.IsNull()) {
508 SymbolTable table(zone, isolate->object_store()->symbol_table());
509 symbol ^= table.GetOrNull(str);
510 table.Release();
511 }
512
513 ASSERT(symbol.IsNull() || symbol.IsSymbol());
514 ASSERT(symbol.IsNull() || symbol.HasHash());
515 return symbol.raw();
516 }
517
518
519 RawString* Symbols::LookupFromConcat(const String& str1, const String& str2) {
520 if (str1.Length() == 0) {
521 return Lookup(str2);
522 } else if (str2.Length() == 0) {
523 return Lookup(str1);
524 } else {
525 return Lookup(ConcatString(str1, str2));
526 }
527 }
528
529
495 RawString* Symbols::New(const String& str) { 530 RawString* Symbols::New(const String& str) {
496 if (str.IsSymbol()) { 531 if (str.IsSymbol()) {
497 return str.raw(); 532 return str.raw();
498 } 533 }
499 return New(str, 0, str.Length()); 534 return New(str, 0, str.Length());
500 } 535 }
501 536
502 537
503 RawString* Symbols::New(const String& str, intptr_t begin_index, intptr_t len) { 538 RawString* Symbols::New(const String& str, intptr_t begin_index, intptr_t len) {
504 return NewSymbol(StringSlice(str, begin_index, len)); 539 return NewSymbol(StringSlice(str, begin_index, len));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { 579 RawObject* Symbols::GetVMSymbol(intptr_t object_id) {
545 ASSERT(IsVMSymbolId(object_id)); 580 ASSERT(IsVMSymbolId(object_id));
546 intptr_t i = (object_id - kMaxPredefinedObjectIds); 581 intptr_t i = (object_id - kMaxPredefinedObjectIds);
547 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) { 582 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) {
548 return symbol_handles_[i]->raw(); 583 return symbol_handles_[i]->raw();
549 } 584 }
550 return Object::null(); 585 return Object::null();
551 } 586 }
552 587
553 } // namespace dart 588 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/symbols.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698