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

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

Issue 11369259: Add one-char string table for faster String.charAt to the VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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
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 #ifndef VM_SYMBOLS_H_ 5 #ifndef VM_SYMBOLS_H_
6 #define VM_SYMBOLS_H_ 6 #define VM_SYMBOLS_H_
7 7
8 #include "vm/object.h" 8 #include "vm/object.h"
9 #include "vm/snapshot_ids.h" 9 #include "vm/snapshot_ids.h"
10 10
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 V(_ExternalFloat64Array, "_ExternalFloat64Array") \ 139 V(_ExternalFloat64Array, "_ExternalFloat64Array") \
140 V(_WeakProperty, "_WeakProperty") \ 140 V(_WeakProperty, "_WeakProperty") \
141 V(InvocationMirror, "_InvocationMirror") \ 141 V(InvocationMirror, "_InvocationMirror") \
142 V(AllocateInvocationMirror, "_allocateInvocationMirror") \ 142 V(AllocateInvocationMirror, "_allocateInvocationMirror") \
143 143
144 // Contains a list of frequently used strings in a canonicalized form. This 144 // Contains a list of frequently used strings in a canonicalized form. This
145 // list is kept in the vm_isolate in order to share the copy across isolates 145 // list is kept in the vm_isolate in order to share the copy across isolates
146 // without having to maintain copies in each isolate. 146 // without having to maintain copies in each isolate.
147 class Symbols : public AllStatic { 147 class Symbols : public AllStatic {
148 public: 148 public:
149 static const uint32_t kMaxOneByteCharCode = 0x7F;
Ivan Posva 2012/11/15 09:07:10 There is no reason to limit this to the maximum on
Florian Schneider 2012/11/15 21:54:42 For now I only want to deal with OneByteStrings in
150
149 // List of strings that are pre created in the vm isolate. 151 // List of strings that are pre created in the vm isolate.
150 enum { 152 enum SymbolId {
151 kIllegal = 0, 153 kIllegal = 0,
152 154
153 #define DEFINE_SYMBOL_INDEX(symbol, literal) \ 155 #define DEFINE_SYMBOL_INDEX(symbol, literal) \
154 k##symbol, 156 k##symbol,
155 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX) 157 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX)
156 #undef DEFINE_SYMBOL_INDEX 158 #undef DEFINE_SYMBOL_INDEX
157 159 kMaxPredefinedId,
Ivan Posva 2012/11/15 09:07:10 This causes us to have a hole in the used strings.
Florian Schneider 2012/11/15 21:54:42 Done. kNullCharId is an alias for kMaxPredefinedId
158 kMaxId, 160 kMaxId = kMaxPredefinedId + kMaxOneByteCharCode + 1,
159 }; 161 };
160 162
161 // Access methods for symbols stored in the vm isolate. 163 // Access methods for symbols stored in the vm isolate.
162 #define DEFINE_SYMBOL_ACCESSOR(symbol, literal) \ 164 #define DEFINE_SYMBOL_ACCESSOR(symbol, literal) \
163 static RawString* symbol() { return predefined_[k##symbol]; } 165 static RawString* symbol() { return predefined_[k##symbol]; }
164 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_ACCESSOR) 166 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_ACCESSOR)
165 #undef DEFINE_SYMBOL_ACCESSOR 167 #undef DEFINE_SYMBOL_ACCESSOR
166 168
167 // Initialize frequently used symbols in the vm isolate. 169 // Initialize frequently used symbols in the vm isolate.
168 static void InitOnce(Isolate* isolate); 170 static void InitOnce(Isolate* isolate);
169 171
170 // Initialize and setup a symbol table for the isolate. 172 // Initialize and setup a symbol table for the isolate.
171 static void SetupSymbolTable(Isolate* isolate); 173 static void SetupSymbolTable(Isolate* isolate);
172 174
173 // Get number of symbols in an isolate's symbol table. 175 // Get number of symbols in an isolate's symbol table.
174 static intptr_t Size(Isolate* isolate); 176 static intptr_t Size(Isolate* isolate);
175 177
176 // Helper functions to create a symbol given a string or set of characters. 178 // Helper functions to create a symbol given a string or set of characters.
177 static RawString* New(const char* str); 179 static RawString* New(const char* str);
178 template<typename T> 180 template<typename T>
179 static RawString* New(const T* characters, intptr_t len); 181 static RawString* New(const T* characters, intptr_t len);
180 static RawString* New(const String& str); 182 static RawString* New(const String& str);
181 static RawString* New(const String& str, 183 static RawString* New(const String& str,
182 intptr_t begin_index, 184 intptr_t begin_index,
183 intptr_t length); 185 intptr_t length);
184 186
185 // Returns char* of predefined symbol. 187 // Returns char* of predefined symbol.
186 static const char* Name(intptr_t symbol); 188 static const char* Name(SymbolId symbol);
189
190 static RawString* FromCharCode(uint32_t char_code);
187 191
188 private: 192 private:
189 enum { 193 enum {
190 kInitialVMIsolateSymtabSize = ((Symbols::kMaxId + 15) & -16), 194 kInitialVMIsolateSymtabSize = ((Symbols::kMaxId + 15) & -16),
191 kInitialSymtabSize = 256 195 kInitialSymtabSize = 256
192 }; 196 };
193 197
194 // Add the string into the VM isolate symbol table. 198 // Add the string into the VM isolate symbol table.
195 static void Add(const Array& symbol_table, const String& str); 199 static void Add(const Array& symbol_table, const String& str);
196 200
(...skipping 30 matching lines...) Expand all
227 friend class SnapshotReader; 231 friend class SnapshotReader;
228 friend class SnapshotWriter; 232 friend class SnapshotWriter;
229 friend class ApiMessageReader; 233 friend class ApiMessageReader;
230 234
231 DISALLOW_COPY_AND_ASSIGN(Symbols); 235 DISALLOW_COPY_AND_ASSIGN(Symbols);
232 }; 236 };
233 237
234 } // namespace dart 238 } // namespace dart
235 239
236 #endif // VM_SYMBOLS_H_ 240 #endif // VM_SYMBOLS_H_
OLDNEW
« no previous file with comments | « runtime/vm/snapshot_test.cc ('k') | runtime/vm/symbols.cc » ('j') | runtime/vm/symbols.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698