Changeset 29068 in webkit
- Timestamp:
- Jan 1, 2008, 11:47:21 AM (18 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r29067 r29068 1 2008-01-01 Darin Adler <[email protected]> 2 3 - rolled scope chain optimization out; it was breaking the world 4 1 5 2008-01-01 Darin Adler <[email protected]> 2 6 -
trunk/JavaScriptCore/kjs/object.h
r29065 r29068 593 593 } 594 594 595 inline void ScopeChain::release() 596 { 597 // This function is only called by deref(), 598 // Deref ensures these conditions are true. 599 ASSERT(_node && _node->refCount == 0); 600 ScopeChainNode *n = _node; 601 do { 602 ScopeChainNode *next = n->next; 603 delete n; 604 n = next; 605 } while (n && --n->refCount == 0); 606 } 607 595 608 inline JSValue* JSObject::toPrimitive(ExecState* exec, JSType preferredType) const 596 609 { -
trunk/JavaScriptCore/kjs/scope_chain.cpp
r29065 r29068 28 28 namespace KJS { 29 29 30 void ScopeChain::push(const ScopeChain &c) 31 { 32 ScopeChainNode **tail = &_node; 33 for (ScopeChainNode *n = c._node; n; n = n->next) { 34 ScopeChainNode *newNode = new ScopeChainNode(*tail, n->object); 35 *tail = newNode; 36 tail = &newNode->next; 37 } 38 } 39 30 40 #ifndef NDEBUG 31 41 -
trunk/JavaScriptCore/kjs/scope_chain.h
r29065 r29068 28 28 29 29 class JSObject; 30 struct ScopeChainHeapNode;30 class ExecState; 31 31 32 structScopeChainNode {33 JSObject* object;34 ScopeChain HeapNode* next;35 };32 class ScopeChainNode { 33 public: 34 ScopeChainNode(ScopeChainNode *n, JSObject *o) 35 : next(n), object(o), refCount(1) { } 36 36 37 struct ScopeChainHeapNode : ScopeChainNode { 37 ScopeChainNode *next; 38 JSObject *object; 38 39 int refCount; 39 40 }; … … 65 66 ~ScopeChain() { deref(); } 66 67 67 ScopeChain(const ScopeChain&); 68 ScopeChain(const ScopeChain &c) : _node(c._node) 69 { if (_node) ++_node->refCount; } 68 70 ScopeChain &operator=(const ScopeChain &); 69 71 … … 78 80 void clear() { deref(); _node = 0; } 79 81 void push(JSObject *); 82 void push(const ScopeChain &); 80 83 void pop(); 81 84 … … 87 90 88 91 private: 89 mutable ScopeChainNode* _node; 90 ScopeChainNode m_initialTopNode; 91 92 ScopeChainHeapNode* moveToHeap() const; 93 94 void deref(); 92 ScopeChainNode *_node; 93 94 void deref() { if (_node && --_node->refCount == 0) release(); } 95 95 void ref() const; 96 97 void release(); 96 98 }; 97 98 inline ScopeChainHeapNode* ScopeChain::moveToHeap() const99 {100 if (_node != &m_initialTopNode)101 return static_cast<ScopeChainHeapNode*>(_node);102 ScopeChainHeapNode* heapNode = new ScopeChainHeapNode;103 heapNode->object = m_initialTopNode.object;104 heapNode->next = m_initialTopNode.next;105 heapNode->refCount = 1;106 _node = heapNode;107 return heapNode;108 }109 110 inline ScopeChain::ScopeChain(const ScopeChain& otherChain)111 {112 if (!otherChain._node)113 _node = 0;114 else {115 ScopeChainHeapNode* top = otherChain.moveToHeap();116 ++top->refCount;117 _node = top;118 }119 }120 99 121 100 inline void ScopeChain::ref() const 122 101 { 123 ASSERT(_node != &m_initialTopNode); 124 for (ScopeChainHeapNode* n = static_cast<ScopeChainHeapNode*>(_node); n; n = n->next) { 125 if (n->refCount++) 102 for (ScopeChainNode *n = _node; n; n = n->next) { 103 if (n->refCount++ != 0) 126 104 break; 127 105 } 128 106 } 129 107 130 inline void ScopeChain::deref()108 inline ScopeChain &ScopeChain::operator=(const ScopeChain &c) 131 109 { 132 ScopeChainHeapNode* node = static_cast<ScopeChainHeapNode*>(_node); 133 if (node == &m_initialTopNode) 134 node = node->next; 135 ScopeChainHeapNode* next; 136 for (; node && --node->refCount == 0; node = next) { 137 next = node->next; 138 delete node; 139 } 140 } 141 142 inline ScopeChain &ScopeChain::operator=(const ScopeChain& otherChain) 143 { 144 otherChain.moveToHeap(); 145 otherChain.ref(); 110 c.ref(); 146 111 deref(); 147 _node = otherChain._node;112 _node = c._node; 148 113 return *this; 149 114 } … … 159 124 } 160 125 161 inline void ScopeChain::push(JSObject *o)126 inline void ScopeChain::push(JSObject *o) 162 127 { 163 128 ASSERT(o); 164 ScopeChainHeapNode* heapNode = moveToHeap(); 165 m_initialTopNode.object = o; 166 m_initialTopNode.next = heapNode; 167 _node = &m_initialTopNode; 129 _node = new ScopeChainNode(_node, o); 168 130 } 169 131 … … 172 134 ScopeChainNode *oldNode = _node; 173 135 ASSERT(oldNode); 174 ScopeChain HeapNode *newNode = oldNode->next;136 ScopeChainNode *newNode = oldNode->next; 175 137 _node = newNode; 176 177 if (oldNode != &m_initialTopNode) { 178 ScopeChainHeapNode* oldHeapNode = static_cast<ScopeChainHeapNode*>(oldNode); 179 if (--oldHeapNode->refCount != 0) { 180 if (newNode) 181 ++newNode->refCount; 182 } else { 183 delete oldHeapNode; 184 } 138 139 if (--oldNode->refCount != 0) { 140 if (newNode) 141 ++newNode->refCount; 142 } else { 143 delete oldNode; 185 144 } 186 145 }
Note:
See TracChangeset
for help on using the changeset viewer.