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