Changeset 29068 in webkit


Ignore:
Timestamp:
Jan 1, 2008, 11:47:21 AM (18 years ago)
Author:
Darin Adler
Message:
  • rolled scope chain optimization out; it was breaking the world
Location:
trunk/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r29067 r29068  
     12008-01-01  Darin Adler  <[email protected]>
     2
     3        - rolled scope chain optimization out; it was breaking the world
     4
    152008-01-01  Darin Adler  <[email protected]>
    26
  • trunk/JavaScriptCore/kjs/object.h

    r29065 r29068  
    593593}
    594594
     595inline 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
    595608inline JSValue* JSObject::toPrimitive(ExecState* exec, JSType preferredType) const
    596609{
  • trunk/JavaScriptCore/kjs/scope_chain.cpp

    r29065 r29068  
    2828namespace KJS {
    2929
     30void 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
    3040#ifndef NDEBUG
    3141
  • trunk/JavaScriptCore/kjs/scope_chain.h

    r29065 r29068  
    2828
    2929    class JSObject;
    30     struct ScopeChainHeapNode;
     30    class ExecState;
    3131   
    32     struct ScopeChainNode {
    33         JSObject* object;
    34         ScopeChainHeapNode* next;
    35     };
     32    class ScopeChainNode {
     33    public:
     34        ScopeChainNode(ScopeChainNode *n, JSObject *o)
     35            : next(n), object(o), refCount(1) { }
    3636
    37     struct ScopeChainHeapNode : ScopeChainNode {
     37        ScopeChainNode *next;
     38        JSObject *object;
    3839        int refCount;
    3940    };
     
    6566        ~ScopeChain() { deref(); }
    6667
    67         ScopeChain(const ScopeChain&);
     68        ScopeChain(const ScopeChain &c) : _node(c._node)
     69            { if (_node) ++_node->refCount; }
    6870        ScopeChain &operator=(const ScopeChain &);
    6971
     
    7880        void clear() { deref(); _node = 0; }
    7981        void push(JSObject *);
     82        void push(const ScopeChain &);
    8083        void pop();
    8184       
     
    8790       
    8891    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(); }
    9595        void ref() const;
     96       
     97        void release();
    9698    };
    97 
    98 inline ScopeChainHeapNode* ScopeChain::moveToHeap() const
    99 {
    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 }
    12099
    121100inline void ScopeChain::ref() const
    122101{
    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)
    126104            break;
    127105    }
    128106}
    129107
    130 inline void ScopeChain::deref()
     108inline ScopeChain &ScopeChain::operator=(const ScopeChain &c)
    131109{
    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();
    146111    deref();
    147     _node = otherChain._node;
     112    _node = c._node;
    148113    return *this;
    149114}
     
    159124}
    160125
    161 inline void ScopeChain::push(JSObject* o)
     126inline void ScopeChain::push(JSObject *o)
    162127{
    163128    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);
    168130}
    169131
     
    172134    ScopeChainNode *oldNode = _node;
    173135    ASSERT(oldNode);
    174     ScopeChainHeapNode *newNode = oldNode->next;
     136    ScopeChainNode *newNode = oldNode->next;
    175137    _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;
    185144    }
    186145}
Note: See TracChangeset for help on using the changeset viewer.