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

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: added characters 0x80..0xff 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 enum { kMaxOneByteCharCode = 0xFF };
Ivan Posva 2012/11/17 01:30:58 kMaxOneCharCodeSymbol or similar. It is not relate
Florian Schneider 2012/11/19 16:04:02 Done.
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,
158 kMaxId, 160 kNullCharId = kMaxPredefinedId,
161 kMaxId = kNullCharId + kMaxOneByteCharCode + 1,
159 }; 162 };
160 163
161 // Access methods for symbols stored in the vm isolate. 164 // Access methods for symbols stored in the vm isolate.
162 #define DEFINE_SYMBOL_ACCESSOR(symbol, literal) \ 165 #define DEFINE_SYMBOL_ACCESSOR(symbol, literal) \
163 static RawString* symbol() { return predefined_[k##symbol]; } 166 static RawString* symbol() { return predefined_[k##symbol]; }
164 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_ACCESSOR) 167 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_ACCESSOR)
165 #undef DEFINE_SYMBOL_ACCESSOR 168 #undef DEFINE_SYMBOL_ACCESSOR
166 169
167 // Initialize frequently used symbols in the vm isolate. 170 // Initialize frequently used symbols in the vm isolate.
168 static void InitOnce(Isolate* isolate); 171 static void InitOnce(Isolate* isolate);
169 172
170 // Initialize and setup a symbol table for the isolate. 173 // Initialize and setup a symbol table for the isolate.
171 static void SetupSymbolTable(Isolate* isolate); 174 static void SetupSymbolTable(Isolate* isolate);
172 175
173 // Get number of symbols in an isolate's symbol table. 176 // Get number of symbols in an isolate's symbol table.
174 static intptr_t Size(Isolate* isolate); 177 static intptr_t Size(Isolate* isolate);
175 178
176 // Helper functions to create a symbol given a string or set of characters. 179 // Helper functions to create a symbol given a string or set of characters.
177 static RawString* New(const char* str); 180 static RawString* New(const char* str);
178 template<typename T> 181 template<typename T>
179 static RawString* New(const T* characters, intptr_t len); 182 static RawString* New(const T* characters, intptr_t len);
180 static RawString* New(const String& str); 183 static RawString* New(const String& str);
181 static RawString* New(const String& str, 184 static RawString* New(const String& str,
182 intptr_t begin_index, 185 intptr_t begin_index,
183 intptr_t length); 186 intptr_t length);
184 187
185 // Returns char* of predefined symbol. 188 // Returns char* of predefined symbol.
186 static const char* Name(intptr_t symbol); 189 static const char* Name(SymbolId symbol);
190
191 static RawString* FromCharCode(uint32_t char_code);
187 192
188 private: 193 private:
189 enum { 194 enum {
190 kInitialVMIsolateSymtabSize = ((Symbols::kMaxId + 15) & -16), 195 kInitialVMIsolateSymtabSize = ((kMaxId + 15) & -16),
191 kInitialSymtabSize = 256 196 kInitialSymtabSize = 256
192 }; 197 };
193 198
194 // Add the string into the VM isolate symbol table. 199 // Add the string into the VM isolate symbol table.
195 static void Add(const Array& symbol_table, const String& str); 200 static void Add(const Array& symbol_table, const String& str);
196 201
197 // Insert symbol into symbol table, growing it if necessary. 202 // Insert symbol into symbol table, growing it if necessary.
198 static void InsertIntoSymbolTable(const Array& symbol_table, 203 static void InsertIntoSymbolTable(const Array& symbol_table,
199 const String& symbol, 204 const String& symbol,
200 intptr_t index); 205 intptr_t index);
(...skipping 10 matching lines...) Expand all
211 intptr_t hash); 216 intptr_t hash);
212 static intptr_t FindIndex(const Array& symbol_table, 217 static intptr_t FindIndex(const Array& symbol_table,
213 const String& str, 218 const String& str,
214 intptr_t begin_index, 219 intptr_t begin_index,
215 intptr_t len, 220 intptr_t len,
216 intptr_t hash); 221 intptr_t hash);
217 static intptr_t LookupVMSymbol(RawObject* obj); 222 static intptr_t LookupVMSymbol(RawObject* obj);
218 static RawObject* GetVMSymbol(intptr_t object_id); 223 static RawObject* GetVMSymbol(intptr_t object_id);
219 static bool IsVMSymbolId(intptr_t object_id) { 224 static bool IsVMSymbolId(intptr_t object_id) {
220 return (object_id >= kMaxPredefinedObjectIds && 225 return (object_id >= kMaxPredefinedObjectIds &&
221 object_id < (kMaxPredefinedObjectIds + Symbols::kMaxId)); 226 object_id < (kMaxPredefinedObjectIds + kMaxId));
222 } 227 }
223 228
224 // List of symbols that are stored in the vm isolate for easy access. 229 // List of symbols that are stored in the vm isolate for easy access.
225 static RawString* predefined_[Symbols::kMaxId]; 230 static RawString* predefined_[kMaxId];
226 231
227 friend class SnapshotReader; 232 friend class SnapshotReader;
228 friend class SnapshotWriter; 233 friend class SnapshotWriter;
229 friend class ApiMessageReader; 234 friend class ApiMessageReader;
230 235
231 DISALLOW_COPY_AND_ASSIGN(Symbols); 236 DISALLOW_COPY_AND_ASSIGN(Symbols);
232 }; 237 };
233 238
234 } // namespace dart 239 } // namespace dart
235 240
236 #endif // VM_SYMBOLS_H_ 241 #endif // VM_SYMBOLS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698