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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/symbols.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/symbols.cc
diff --git a/runtime/vm/symbols.cc b/runtime/vm/symbols.cc
index c827704d682d75f9f8a63d56c75a2e50595e3845..03e6c6867545916e622b4c554fb4a16cbc910749 100644
--- a/runtime/vm/symbols.cc
+++ b/runtime/vm/symbols.cc
@@ -492,6 +492,41 @@ RawString* Symbols::NewSymbol(const StringType& str) {
}
+template<typename StringType>
+RawString* Symbols::Lookup(const StringType& str) {
+ Thread* thread = Thread::Current();
+ Isolate* isolate = thread->isolate();
+ Zone* zone = thread->zone();
+ String& symbol = String::Handle(zone);
+ {
+ Isolate* vm_isolate = Dart::vm_isolate();
+ SymbolTable table(zone, vm_isolate->object_store()->symbol_table());
+ symbol ^= table.GetOrNull(str);
+ table.Release();
+ }
+ if (symbol.IsNull()) {
+ SymbolTable table(zone, isolate->object_store()->symbol_table());
+ symbol ^= table.GetOrNull(str);
+ table.Release();
+ }
+
+ ASSERT(symbol.IsNull() || symbol.IsSymbol());
+ ASSERT(symbol.IsNull() || symbol.HasHash());
+ return symbol.raw();
+}
+
+
+RawString* Symbols::LookupFromConcat(const String& str1, const String& str2) {
+ if (str1.Length() == 0) {
+ return Lookup(str2);
+ } else if (str2.Length() == 0) {
+ return Lookup(str1);
+ } else {
+ return Lookup(ConcatString(str1, str2));
+ }
+}
+
+
RawString* Symbols::New(const String& str) {
if (str.IsSymbol()) {
return str.raw();
« 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