Changeset 47571 in webkit for trunk/JavaScriptCore/parser/ParserArena.h
- Timestamp:
- Aug 20, 2009, 7:24:49 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/parser/ParserArena.h
r43661 r47571 27 27 #define ParserArena_h 28 28 29 #include <wtf/PassRefPtr.h> 30 #include <wtf/RefPtr.h> 31 #include <wtf/Vector.h> 29 #include "Identifier.h" 30 #include <wtf/SegmentedVector.h> 32 31 33 32 namespace JSC { … … 36 35 class ParserArenaRefCounted; 37 36 38 class ParserArena {37 class IdentifierArena { 39 38 public: 39 ALWAYS_INLINE const Identifier& makeIdentifier(JSGlobalData*, const UChar* characters, size_t length); 40 const Identifier& makeNumericIdentifier(JSGlobalData*, double number); 41 42 void clear() { m_identifiers.clear(); } 43 bool isEmpty() const { return m_identifiers.isEmpty(); } 44 45 private: 46 typedef SegmentedVector<Identifier, 64> IdentifierVector; 47 IdentifierVector m_identifiers; 48 }; 49 50 ALWAYS_INLINE const Identifier& IdentifierArena::makeIdentifier(JSGlobalData* globalData, const UChar* characters, size_t length) 51 { 52 m_identifiers.append(Identifier(globalData, characters, length)); 53 return m_identifiers.last(); 54 } 55 56 inline const Identifier& IdentifierArena::makeNumericIdentifier(JSGlobalData* globalData, double number) 57 { 58 m_identifiers.append(Identifier(globalData, UString::from(number))); 59 return m_identifiers.last(); 60 } 61 62 class ParserArena : Noncopyable { 63 public: 64 ParserArena(); 65 ~ParserArena(); 66 40 67 void swap(ParserArena& otherArena) 41 68 { 69 std::swap(m_freeableMemory, otherArena.m_freeableMemory); 70 std::swap(m_freeablePoolEnd, otherArena.m_freeablePoolEnd); 71 m_identifierArena.swap(otherArena.m_identifierArena); 72 m_freeablePools.swap(otherArena.m_freeablePools); 42 73 m_deletableObjects.swap(otherArena.m_deletableObjects); 43 74 m_refCountedObjects.swap(otherArena.m_refCountedObjects); 44 75 } 45 ~ParserArena();46 76 47 void deleteWithArena(ParserArenaDeletable* object) { m_deletableObjects.append(object); } 77 void* allocateFreeable(size_t size) 78 { 79 ASSERT(size); 80 ASSERT(size <= freeablePoolSize); 81 size_t alignedSize = alignSize(size); 82 ASSERT(alignedSize <= freeablePoolSize); 83 if (UNLIKELY(static_cast<size_t>(m_freeablePoolEnd - m_freeableMemory) < alignedSize)) 84 allocateFreeablePool(); 85 void* block = m_freeableMemory; 86 m_freeableMemory += alignedSize; 87 return block; 88 } 89 90 void* allocateDeletable(size_t size) 91 { 92 ParserArenaDeletable* deletable = static_cast<ParserArenaDeletable*>(fastMalloc(size)); 93 m_deletableObjects.append(deletable); 94 return deletable; 95 } 96 48 97 void derefWithArena(PassRefPtr<ParserArenaRefCounted> object) { m_refCountedObjects.append(object); } 49 50 98 bool contains(ParserArenaRefCounted*) const; 51 99 ParserArenaRefCounted* last() const; 52 100 void removeLast(); 53 101 54 bool isEmpty() const { return m_deletableObjects.isEmpty() && m_refCountedObjects.isEmpty(); }102 bool isEmpty() const; 55 103 void reset(); 56 104 105 IdentifierArena& identifierArena() { return *m_identifierArena; } 106 57 107 private: 108 static const size_t freeablePoolSize = 8000; 109 110 static size_t alignSize(size_t size) 111 { 112 return (size + sizeof(WTF::AllocAlignmentInteger) - 1) & ~(sizeof(WTF::AllocAlignmentInteger) - 1); 113 } 114 115 void* freeablePool(); 116 void allocateFreeablePool(); 117 void deallocateObjects(); 118 119 char* m_freeableMemory; 120 char* m_freeablePoolEnd; 121 122 OwnPtr<IdentifierArena> m_identifierArena; 123 Vector<void*> m_freeablePools; 58 124 Vector<ParserArenaDeletable*> m_deletableObjects; 59 125 Vector<RefPtr<ParserArenaRefCounted> > m_refCountedObjects;
Note:
See TracChangeset
for help on using the changeset viewer.