Changeset 11296 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Nov 26, 2005, 5:28:30 PM (20 years ago)
Author:
eseidel
Message:

Bug #: 5687
Submitted by: darin
Reviewed by: eseidel

Inline ScopeChain functions for speed.
http://bugzilla.opendarwin.org/show_bug.cgi?id=5687

  • kjs/object.h: (KJS::ScopeChain::mark):
  • kjs/scope_chain.cpp:
  • kjs/scope_chain.h: (KJS::ScopeChain::ref): (KJS::ScopeChain::operator=): (KJS::ScopeChain::bottom): (KJS::ScopeChain::push): (KJS::ScopeChain::pop):
Location:
trunk/JavaScriptCore/kjs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/object.h

    r10857 r11296  
    607607}
    608608
     609// FIXME: Put this function in a separate file named something like scope_chain_mark.h -- can't put it in scope_chain.h since it depends on ObjectImp.
     610
     611inline void ScopeChain::mark()
     612{
     613    for (ScopeChainNode *n = _node; n; n = n->next) {
     614        ObjectImp *o = n->object;
     615        if (!o->marked())
     616            o->mark();
     617    }
     618}
     619
    609620} // namespace
    610621
  • trunk/JavaScriptCore/kjs/scope_chain.cpp

    r10701 r11296  
    2323#include "scope_chain.h"
    2424
    25 #include "object.h"
    26 
    2725namespace KJS {
    28 
    29 inline void ScopeChain::ref() const
    30 {
    31     for (ScopeChainNode *n = _node; n; n = n->next) {
    32         if (n->refCount++ != 0)
    33             break;
    34     }
    35 }
    36 
    37 ScopeChain &ScopeChain::operator=(const ScopeChain &c)
    38 {
    39     c.ref();
    40     deref();
    41     _node = c._node;
    42     return *this;
    43 }
    44 
    45 void ScopeChain::push(ObjectImp *o)
    46 {
    47     assert(o);
    48     _node = new ScopeChainNode(_node, o);
    49 }
    5026
    5127void ScopeChain::push(const ScopeChain &c)
     
    5632        *tail = newNode;
    5733        tail = &newNode->next;
    58     }
    59 }
    60 
    61 void ScopeChain::pop()
    62 {
    63     ScopeChainNode *oldNode = _node;
    64     assert(oldNode);
    65     ScopeChainNode *newNode = oldNode->next;
    66     _node = newNode;
    67    
    68     if (--oldNode->refCount != 0) {
    69         if (newNode)
    70             ++newNode->refCount;
    71     } else {
    72         delete oldNode;
    7334    }
    7435}
     
    8748}
    8849
    89 void ScopeChain::mark()
    90 {
    91     for (ScopeChainNode *n = _node; n; n = n->next) {
    92         ObjectImp *o = n->object;
    93         if (!o->marked())
    94             o->mark();
    95     }
    96 }
    97 
    98 ObjectImp *ScopeChain::bottom() const
    99 {
    100     ScopeChainNode *last = 0;
    101     for (ScopeChainNode *n = _node; n; n = n->next) {
    102         if (!n->next) {
    103             last = n;
    104         }
    105     }
    106     if (!last) {
    107         return 0;
    108     }
    109 
    110     return last->object;
    111 }
    112 
    11350} // namespace KJS
  • trunk/JavaScriptCore/kjs/scope_chain.h

    r10701 r11296  
    2222#ifndef KJS_SCOPE_CHAIN_H
    2323#define KJS_SCOPE_CHAIN_H
     24
     25#include <assert.h>
    2426
    2527namespace KJS {
     
    8890    };
    8991
     92inline void ScopeChain::ref() const
     93{
     94    for (ScopeChainNode *n = _node; n; n = n->next) {
     95        if (n->refCount++ != 0)
     96            break;
     97    }
     98}
     99
     100inline ScopeChain &ScopeChain::operator=(const ScopeChain &c)
     101{
     102    c.ref();
     103    deref();
     104    _node = c._node;
     105    return *this;
     106}
     107
     108inline ObjectImp *ScopeChain::bottom() const
     109{
     110    ScopeChainNode *last = 0;
     111    for (ScopeChainNode *n = _node; n; n = n->next)
     112        last = n;
     113    if (!last)
     114        return 0;
     115    return last->object;
     116}
     117
     118inline void ScopeChain::push(ObjectImp *o)
     119{
     120    assert(o);
     121    _node = new ScopeChainNode(_node, o);
     122}
     123
     124inline void ScopeChain::pop()
     125{
     126    ScopeChainNode *oldNode = _node;
     127    assert(oldNode);
     128    ScopeChainNode *newNode = oldNode->next;
     129    _node = newNode;
     130   
     131    if (--oldNode->refCount != 0) {
     132        if (newNode)
     133            ++newNode->refCount;
     134    } else {
     135        delete oldNode;
     136    }
     137}
     138
    90139} // namespace KJS
    91140
Note: See TracChangeset for help on using the changeset viewer.