Changeset 47582 in webkit for trunk/JavaScriptCore/parser/ParserArena.h
- Timestamp:
- Aug 20, 2009, 11:04:37 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/parser/ParserArena.h
r47573 r47582 27 27 #define ParserArena_h 28 28 29 #include "Identifier.h" 30 #include <wtf/SegmentedVector.h> 29 #include <wtf/PassRefPtr.h> 30 #include <wtf/RefPtr.h> 31 #include <wtf/Vector.h> 31 32 32 33 namespace JSC { … … 35 36 class ParserArenaRefCounted; 36 37 37 class IdentifierArena {38 class ParserArena { 38 39 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 67 40 void swap(ParserArena& otherArena) 68 41 { 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);73 42 m_deletableObjects.swap(otherArena.m_deletableObjects); 74 43 m_refCountedObjects.swap(otherArena.m_refCountedObjects); 75 44 } 45 ~ParserArena(); 76 46 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 } 47 void deleteWithArena(ParserArenaDeletable* object) { m_deletableObjects.append(object); } 48 void derefWithArena(PassRefPtr<ParserArenaRefCounted> object) { m_refCountedObjects.append(object); } 89 49 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 97 void derefWithArena(PassRefPtr<ParserArenaRefCounted>);98 50 bool contains(ParserArenaRefCounted*) const; 99 51 ParserArenaRefCounted* last() const; 100 52 void removeLast(); 101 53 102 bool isEmpty() const ;54 bool isEmpty() const { return m_deletableObjects.isEmpty() && m_refCountedObjects.isEmpty(); } 103 55 void reset(); 104 56 105 IdentifierArena& identifierArena() { return *m_identifierArena; }106 107 57 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;124 58 Vector<ParserArenaDeletable*> m_deletableObjects; 125 59 Vector<RefPtr<ParserArenaRefCounted> > m_refCountedObjects;
Note:
See TracChangeset
for help on using the changeset viewer.