OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #ifndef VM_SYMBOLS_H_ |
| 6 #define VM_SYMBOLS_H_ |
| 7 |
| 8 #include "vm/object.h" |
| 9 |
| 10 namespace dart { |
| 11 |
| 12 // Forward declarations. |
| 13 class Isolate; |
| 14 class ObjectPointerVisitor; |
| 15 |
| 16 // Contains a list of frequently used strings in a canonicalized form. This |
| 17 // list is kept in the vm_isolate in order to share the copy across isolates |
| 18 // without having to maintain copies in each isolate. |
| 19 class Symbols : public AllStatic { |
| 20 public: |
| 21 // List of strings that are pre created in the vm isolate. |
| 22 static const char* kDot; |
| 23 |
| 24 // Access methods for symbols stored in the vm isolate. |
| 25 static RawString* Dot() { return dot_; } |
| 26 |
| 27 // Initialize frequently used symbols in the vm isolate. |
| 28 static void InitOnce(Isolate* isolate); |
| 29 |
| 30 // Initialize and setup a symbol table for the isolate. |
| 31 static void SetupSymbolTable(Isolate* isolate); |
| 32 |
| 33 // Helper functions to create a symbol given a string or set of characters. |
| 34 static RawString* New(const char* str); |
| 35 template<typename T> |
| 36 static RawString* New(const T* characters, intptr_t len); |
| 37 static RawString* New(const String& str); |
| 38 static RawString* New(const String& str, |
| 39 intptr_t begin_index, |
| 40 intptr_t length); |
| 41 |
| 42 |
| 43 private: |
| 44 static const int kInitialSymbolTableSize = 16; |
| 45 |
| 46 // Add the string into the VM isolate symbol table. |
| 47 static void Add(const Array& symbol_table, const String& str); |
| 48 |
| 49 // Insert symbol into symbol table, growing it if necessary. |
| 50 static void InsertIntoSymbolTable(const Array& symbol_table, |
| 51 const String& symbol, |
| 52 intptr_t index); |
| 53 |
| 54 // Grow the symbol table. |
| 55 static void GrowSymbolTable(const Array& symbol_table); |
| 56 |
| 57 // Return index in symbol table if the symbol already exists or |
| 58 // return the index into which the new symbol can be added. |
| 59 template<typename T> |
| 60 static intptr_t FindIndex(const Array& symbol_table, |
| 61 const T* characters, |
| 62 intptr_t len, |
| 63 intptr_t hash); |
| 64 static intptr_t FindIndex(const Array& symbol_table, |
| 65 const String& str, |
| 66 intptr_t begin_index, |
| 67 intptr_t len, |
| 68 intptr_t hash); |
| 69 |
| 70 // List of symbols that are stored in the vm isolate for easy access. |
| 71 static RawString* dot_; // "." string. |
| 72 |
| 73 friend class SnapshotReader; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(Symbols); |
| 76 }; |
| 77 |
| 78 } // namespace dart |
| 79 |
| 80 #endif // VM_SYMBOLS_H_ |
OLD | NEW |