Changeset 2741 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Nov 18, 2002, 5:01:16 PM (23 years ago)
Author:
mjs
Message:

JavaScriptCore:

Partway to removing Value from List. Created a marking List
variant, used it in place of ListImp.

  • kjs/internal.h: Removed List stuff.
  • kjs/internal.cpp: (InterpreterImp::mark): Call appropriate List method to do marking of empty ListImp.
  • kjs/object.h:
  • kjs/object.cpp: Use marking List instead of ListImp *.
  • kjs/types.h:
  • kjs/types.cpp: (List::List): New boolean needsMarking parameter. (List::operator=): Perform trickery related to needsMarking. (List::~List): Likewise. (List::mark): Mark the ListImp. (List::markEmptyList): (ListImp::*): Moved here fron internal.cpp, they will be integrated into the relevant List methods soon.

WebCore:

  • force-js-clean-timestamp: Rebuild for JSC changes.
Location:
trunk/JavaScriptCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r2740 r2741  
     12002-11-18  Maciej Stachowiak  <[email protected]>
     2
     3        Partway to removing Value from List. Created a marking List
     4        variant, used it in place of ListImp.
     5       
     6        * kjs/internal.h: Removed List stuff.
     7        * kjs/internal.cpp:
     8        (InterpreterImp::mark): Call appropriate List method to do marking of
     9        empty ListImp.
     10        * kjs/object.h:
     11        * kjs/object.cpp: Use marking List instead of ListImp *.
     12        * kjs/types.h:
     13        * kjs/types.cpp:
     14        (List::List): New boolean needsMarking parameter.
     15        (List::operator=): Perform trickery related to needsMarking.
     16        (List::~List): Likewise.
     17        (List::mark): Mark the ListImp.
     18        (List::markEmptyList):
     19        (ListImp::*): Moved here fron internal.cpp, they will be
     20        integrated into the relevant List methods soon.
     21
    1222002-11-18  Darin Adler  <[email protected]>
    223
  • trunk/JavaScriptCore/ChangeLog-2002-12-03

    r2740 r2741  
     12002-11-18  Maciej Stachowiak  <[email protected]>
     2
     3        Partway to removing Value from List. Created a marking List
     4        variant, used it in place of ListImp.
     5       
     6        * kjs/internal.h: Removed List stuff.
     7        * kjs/internal.cpp:
     8        (InterpreterImp::mark): Call appropriate List method to do marking of
     9        empty ListImp.
     10        * kjs/object.h:
     11        * kjs/object.cpp: Use marking List instead of ListImp *.
     12        * kjs/types.h:
     13        * kjs/types.cpp:
     14        (List::List): New boolean needsMarking parameter.
     15        (List::operator=): Perform trickery related to needsMarking.
     16        (List::~List): Likewise.
     17        (List::mark): Mark the ListImp.
     18        (List::markEmptyList):
     19        (ListImp::*): Moved here fron internal.cpp, they will be
     20        integrated into the relevant List methods soon.
     21
    1222002-11-18  Darin Adler  <[email protected]>
    223
  • trunk/JavaScriptCore/ChangeLog-2003-10-25

    r2740 r2741  
     12002-11-18  Maciej Stachowiak  <[email protected]>
     2
     3        Partway to removing Value from List. Created a marking List
     4        variant, used it in place of ListImp.
     5       
     6        * kjs/internal.h: Removed List stuff.
     7        * kjs/internal.cpp:
     8        (InterpreterImp::mark): Call appropriate List method to do marking of
     9        empty ListImp.
     10        * kjs/object.h:
     11        * kjs/object.cpp: Use marking List instead of ListImp *.
     12        * kjs/types.h:
     13        * kjs/types.cpp:
     14        (List::List): New boolean needsMarking parameter.
     15        (List::operator=): Perform trickery related to needsMarking.
     16        (List::~List): Likewise.
     17        (List::mark): Mark the ListImp.
     18        (List::markEmptyList):
     19        (ListImp::*): Moved here fron internal.cpp, they will be
     20        integrated into the relevant List methods soon.
     21
    1222002-11-18  Darin Adler  <[email protected]>
    223
  • trunk/JavaScriptCore/kjs/internal.cpp

    r2483 r2741  
    332332}
    333333
    334 // ------------------------------ ListImp --------------------------------------
    335 
    336 #ifdef KJS_DEBUG_MEM
    337 int ListImp::count = 0;
    338 #endif
    339 
    340 Value ListImp::toPrimitive(ExecState */*exec*/, Type /*preferredType*/) const
    341 {
    342   // invalid for List
    343   assert(false);
    344   return Value();
    345 }
    346 
    347 bool ListImp::toBoolean(ExecState */*exec*/) const
    348 {
    349   // invalid for List
    350   assert(false);
    351   return false;
    352 }
    353 
    354 double ListImp::toNumber(ExecState */*exec*/) const
    355 {
    356   // invalid for List
    357   assert(false);
    358   return 0;
    359 }
    360 
    361 UString ListImp::toString(ExecState */*exec*/) const
    362 {
    363   // invalid for List
    364   assert(false);
    365   return UString::null;
    366 }
    367 
    368 Object ListImp::toObject(ExecState */*exec*/) const
    369 {
    370   // invalid for List
    371   assert(false);
    372   return Object();
    373 }
    374 
    375 ListImp::ListImp()
    376 {
    377 #ifdef KJS_DEBUG_MEM
    378   count++;
    379 #endif
    380 
    381   hook = new ListNode(Null(), 0L, 0L);
    382   hook->next = hook;
    383   hook->prev = hook;
    384   //fprintf(stderr,"ListImp::ListImp %p hook=%p\n",this,hook);
    385 }
    386 
    387 ListImp::~ListImp()
    388 {
    389   //fprintf(stderr,"ListImp::~ListImp %p\n",this);
    390 #ifdef KJS_DEBUG_MEM
    391   count--;
    392 #endif
    393 
    394   clear();
    395   delete hook;
    396 
    397   if ( emptyList == this )
    398     emptyList = 0L;
    399 }
    400 
    401 void ListImp::mark()
    402 {
    403   ListNode *n = hook->next;
    404   while (n != hook) {
    405     if (!n->member->marked())
    406       n->member->mark();
    407     n = n->next;
    408   }
    409   ValueImp::mark();
    410 }
    411 
    412 void ListImp::append(const Value& obj)
    413 {
    414   ListNode *n = new ListNode(obj, hook->prev, hook);
    415   hook->prev->next = n;
    416   hook->prev = n;
    417 }
    418 
    419 void ListImp::prepend(const Value& obj)
    420 {
    421   ListNode *n = new ListNode(obj, hook, hook->next);
    422   hook->next->prev = n;
    423   hook->next = n;
    424 }
    425 
    426 void ListImp::appendList(const List& lst)
    427 {
    428   ListIterator it = lst.begin();
    429   ListIterator e = lst.end();
    430   while(it != e) {
    431     append(*it);
    432     ++it;
    433   }
    434 }
    435 
    436 void ListImp::prependList(const List& lst)
    437 {
    438   ListIterator it = lst.end();
    439   ListIterator e = lst.begin();
    440   while(it != e) {
    441     --it;
    442     prepend(*it);
    443   }
    444 }
    445 
    446 void ListImp::removeFirst()
    447 {
    448   erase(hook->next);
    449 }
    450 
    451 void ListImp::removeLast()
    452 {
    453   erase(hook->prev);
    454 }
    455 
    456 void ListImp::remove(const Value &obj)
    457 {
    458   if (obj.isNull())
    459     return;
    460   ListNode *n = hook->next;
    461   while (n != hook) {
    462     if (n->member == obj.imp()) {
    463       erase(n);
    464       return;
    465     }
    466     n = n->next;
    467   }
    468 }
    469 
    470 void ListImp::clear()
    471 {
    472   ListNode *n = hook->next;
    473   while (n != hook) {
    474     n = n->next;
    475     delete n->prev;
    476   }
    477 
    478   hook->next = hook;
    479   hook->prev = hook;
    480 }
    481 
    482 ListImp *ListImp::copy() const
    483 {
    484   ListImp* newList = new ListImp;
    485 
    486   ListIterator e = end();
    487   ListIterator it = begin();
    488 
    489   while(it != e) {
    490     newList->append(*it);
    491     ++it;
    492   }
    493 
    494   //fprintf( stderr, "ListImp::copy returning newList=%p\n", newList );
    495   return newList;
    496 }
    497 
    498 void ListImp::erase(ListNode *n)
    499 {
    500   if (n != hook) {
    501     n->next->prev = n->prev;
    502     n->prev->next = n->next;
    503     delete n;
    504   }
    505 }
    506 
    507 bool ListImp::isEmpty() const
    508 {
    509   return (hook->prev == hook);
    510 }
    511 
    512 int ListImp::size() const
    513 {
    514   int s = 0;
    515   ListNode *node = hook;
    516   while ((node = node->next) != hook)
    517     s++;
    518 
    519   return s;
    520 }
    521 
    522 Value ListImp::at(int i) const
    523 {
    524   if (i < 0 || i >= size())
    525     return Undefined();
    526 
    527   ListIterator it = begin();
    528   int j = 0;
    529   while ((j++ < i))
    530     it++;
    531 
    532   return *it;
    533 }
    534 
    535 ListImp *ListImp::emptyList = 0L;
    536 
    537 ListImp *ListImp::empty()
    538 {
    539   if (!emptyList)
    540     emptyList = new ListImp();
    541   return emptyList;
    542 }
    543 
    544334// ------------------------------ ContextImp -----------------------------------
    545335
     
    878668  if (BooleanImp::staticFalse && !BooleanImp::staticFalse->marked())
    879669    BooleanImp::staticFalse->mark();
    880   if (ListImp::emptyList && !ListImp::emptyList->marked())
    881     ListImp::emptyList->mark();
     670  List::markEmptyList();
    882671  //fprintf( stderr, "InterpreterImp::mark this=%p global.imp()=%p\n", this, global.imp() );
    883672  if (global.imp())
  • trunk/JavaScriptCore/kjs/internal.h

    r2256 r2741  
    139139  inline Number::Number(NumberImp *imp) : Value(imp) { }
    140140
    141   // ---------------------------------------------------------------------------
    142   //                            Internal type impls
    143   // ---------------------------------------------------------------------------
    144 
    145   /**
    146    * @internal
    147    */
    148   class ListNode {
    149     friend class List;
    150     friend class ListImp;
    151     friend class ListIterator;
    152     ListNode(Value val, ListNode *p, ListNode *n)
    153       : member(val.imp()), prev(p), next(n) {};
    154     ValueImp *member;
    155     ListNode *prev, *next;
    156   };
    157 
    158   class ListImp : public ValueImp {
    159     friend class ListIterator;
    160     friend class List;
    161     friend class InterpreterImp;
    162     friend class ObjectImp;
    163   private:
    164     ListImp();
    165     ~ListImp();
    166 
    167     Type type() const { return ListType; }
    168 
    169     virtual void mark();
    170 
    171     Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
    172     bool toBoolean(ExecState *exec) const;
    173     double toNumber(ExecState *exec) const;
    174     UString toString(ExecState *exec) const;
    175     Object toObject(ExecState *exec) const;
    176 
    177     void append(const Value& val);
    178     void prepend(const Value& val);
    179     void appendList(const List& lst);
    180     void prependList(const List& lst);
    181     void removeFirst();
    182     void removeLast();
    183     void remove(const Value &val);
    184     void clear();
    185     ListImp *copy() const;
    186     ListIterator begin() const { return ListIterator(hook->next); }
    187     ListIterator end() const { return ListIterator(hook); }
    188     //    bool isEmpty() const { return (hook->prev == hook); }
    189     bool isEmpty() const;
    190     int size() const;
    191     Value at(int i) const;
    192     Value operator[](int i) const { return at(i); }
    193     static ListImp* empty();
    194 
    195 #ifdef KJS_DEBUG_MEM
    196     static int count;
    197 #endif
    198   private:
    199     void erase(ListNode *n);
    200     ListNode *hook;
    201     static ListImp *emptyList;
    202   };
    203  
    204   inline List::List(ListImp *imp) : Value(imp) { }
    205 
    206141  /**
    207142   * @short The "label set" in Ecma-262 spec
  • trunk/JavaScriptCore/kjs/object.cpp

    r2740 r2741  
    6262
    6363ObjectImp::ObjectImp(const Object &proto)
    64   : _prop(0), _proto(static_cast<ObjectImp*>(proto.imp())), _internalValue(0L), _scope(0)
     64  : _prop(0), _proto(static_cast<ObjectImp*>(proto.imp())), _internalValue(0L), _scope(true)
    6565{
    6666  //fprintf(stderr,"ObjectImp::ObjectImp %p\n",(void*)this);
    67   _scope = ListImp::empty();
    68   _scope->setGcAllowed();
    6967  _prop = new PropertyMap();
    7068}
    7169
    72 ObjectImp::ObjectImp()
     70ObjectImp::ObjectImp() :
     71  _scope(true)
    7372{
    7473  //fprintf(stderr,"ObjectImp::ObjectImp %p\n",(void*)this);
     
    7675  _proto = NullImp::staticNull;
    7776  _internalValue = 0L;
    78   _scope = ListImp::empty();
    79   _scope->setGcAllowed();
    8077  _prop = new PropertyMap();
    8178}
     
    9996  if (_internalValue && !_internalValue->marked())
    10097    _internalValue->mark();
    101   if (_scope && !_scope->marked())
    102     _scope->mark();
     98
     99  _scope.mark();
    103100}
    104101
     
    391388void ObjectImp::setScope(const List &s)
    392389{
    393   if (_scope) _scope->setGcAllowed();
    394   _scope = static_cast<ListImp*>(s.imp());
     390  _scope = s;
    395391}
    396392
  • trunk/JavaScriptCore/kjs/object.h

    r2740 r2741  
    588588    ValueImp *_proto;
    589589    ValueImp *_internalValue;
    590     ListImp *_scope;
     590    List _scope;
    591591  };
    592592
  • trunk/JavaScriptCore/kjs/types.cpp

    r2256 r2741  
    3939using namespace KJS;
    4040
     41namespace KJS {
     42  // ---------------------------------------------------------------------------
     43  //                            Internal type impls
     44  // ---------------------------------------------------------------------------
     45
     46  /**
     47   * @internal
     48   */
     49  class ListNode {
     50    friend class List;
     51    friend class ListImp;
     52    friend class ListIterator;
     53    ListNode(Value val, ListNode *p, ListNode *n)
     54      : member(val.imp()), prev(p), next(n) {};
     55    ValueImp *member;
     56    ListNode *prev, *next;
     57  };
     58
     59  class ListImp : public ValueImp {
     60    friend class ListIterator;
     61    friend class List;
     62    friend class InterpreterImp;
     63    friend class ObjectImp;
     64  private:
     65    ListImp();
     66    ~ListImp();
     67
     68    Type type() const { return ListType; }
     69
     70    virtual void mark();
     71
     72    Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
     73    bool toBoolean(ExecState *exec) const;
     74    double toNumber(ExecState *exec) const;
     75    UString toString(ExecState *exec) const;
     76    Object toObject(ExecState *exec) const;
     77
     78    void append(const Value& val);
     79    void prepend(const Value& val);
     80    void appendList(const List& lst);
     81    void prependList(const List& lst);
     82    void removeFirst();
     83    void removeLast();
     84    void remove(const Value &val);
     85    void clear();
     86    ListImp *copy() const;
     87    ListIterator begin() const { return ListIterator(hook->next); }
     88    ListIterator end() const { return ListIterator(hook); }
     89    //    bool isEmpty() const { return (hook->prev == hook); }
     90    bool isEmpty() const;
     91    int size() const;
     92    Value at(int i) const;
     93    Value operator[](int i) const { return at(i); }
     94    static ListImp* empty();
     95
     96#ifdef KJS_DEBUG_MEM
     97    static int count;
     98#endif
     99  private:
     100    void erase(ListNode *n);
     101    ListNode *hook;
     102    static ListImp *emptyList;
     103  };
     104 
     105}
     106
     107
    41108// ------------------------------ ListIterator ---------------------------------
    42109
     
    57124}
    58125
    59     //    operator Value* () const { return node->member; }
     126//    operator Value* () const { return node->member; }
    60127Value ListIterator::operator*() const
    61128{
     
    63130}
    64131
    65     //    operator Value*() const { return node->member; }
     132//    operator Value*() const { return node->member; }
    66133Value ListIterator::operator++()
    67134{
     
    102169// ------------------------------ List -----------------------------------------
    103170
    104 List::List()
    105   : Value(new ListImp())
    106 {
    107   //fprintf(stderr,"List::List() this=%p imp=%p refcount=%d\n",this,rep,rep->refcount);
     171List::List(bool needsMarking)
     172  : Value(needsMarking ? ListImp::empty() : new ListImp()),
     173    m_needsMarking(needsMarking)
     174{
     175  if (m_needsMarking) {
     176    imp()->deref();
     177  }
     178}
     179
     180
     181List::List(const List& l)
     182  : Value(l),
     183    m_needsMarking(false)
     184
     185}
     186
     187List::List(ListImp *imp)
     188  : Value(imp),
     189    m_needsMarking(false)
     190{
     191}
     192
     193
     194List& List::operator=(const List& l)
     195{
     196  if (m_needsMarking) {
     197    imp()->ref();
     198  }
     199
     200  Value::operator=(l);
     201
     202  if (m_needsMarking) {
     203    imp()->deref();
     204  }
     205
     206  return *this;
     207}
     208     
     209List::~List()
     210{
     211  if (m_needsMarking) {
     212    imp()->ref();
     213  }
     214}
     215
     216void List::mark()
     217{
     218  if (!imp()->marked()) {
     219    imp()->mark();
     220  }
    108221}
    109222
     
    196309#endif
    197310
     311void List::markEmptyList()
     312{
     313  if (ListImp::emptyList && !ListImp::emptyList->marked())
     314    ListImp::emptyList->mark();
     315}
     316
     317
     318// ------------------------------ ListImp --------------------------------------
     319
     320#ifdef KJS_DEBUG_MEM
     321int ListImp::count = 0;
     322#endif
     323
     324Value ListImp::toPrimitive(ExecState */*exec*/, Type /*preferredType*/) const
     325{
     326  // invalid for List
     327  assert(false);
     328  return Value();
     329}
     330
     331bool ListImp::toBoolean(ExecState */*exec*/) const
     332{
     333  // invalid for List
     334  assert(false);
     335  return false;
     336}
     337
     338double ListImp::toNumber(ExecState */*exec*/) const
     339{
     340  // invalid for List
     341  assert(false);
     342  return 0;
     343}
     344
     345UString ListImp::toString(ExecState */*exec*/) const
     346{
     347  // invalid for List
     348  assert(false);
     349  return UString::null;
     350}
     351
     352Object ListImp::toObject(ExecState */*exec*/) const
     353{
     354  // invalid for List
     355  assert(false);
     356  return Object();
     357}
     358
     359ListImp::ListImp()
     360{
     361#ifdef KJS_DEBUG_MEM
     362  count++;
     363#endif
     364
     365  hook = new ListNode(Null(), 0L, 0L);
     366  hook->next = hook;
     367  hook->prev = hook;
     368  //fprintf(stderr,"ListImp::ListImp %p hook=%p\n",this,hook);
     369}
     370
     371ListImp::~ListImp()
     372{
     373  //fprintf(stderr,"ListImp::~ListImp %p\n",this);
     374#ifdef KJS_DEBUG_MEM
     375  count--;
     376#endif
     377
     378  clear();
     379  delete hook;
     380
     381  if ( emptyList == this )
     382    emptyList = 0L;
     383}
     384
     385void ListImp::mark()
     386{
     387  ListNode *n = hook->next;
     388  while (n != hook) {
     389    if (!n->member->marked())
     390      n->member->mark();
     391    n = n->next;
     392  }
     393  ValueImp::mark();
     394}
     395
     396void ListImp::append(const Value& obj)
     397{
     398  ListNode *n = new ListNode(obj, hook->prev, hook);
     399  hook->prev->next = n;
     400  hook->prev = n;
     401}
     402
     403void ListImp::prepend(const Value& obj)
     404{
     405  ListNode *n = new ListNode(obj, hook, hook->next);
     406  hook->next->prev = n;
     407  hook->next = n;
     408}
     409
     410void ListImp::appendList(const List& lst)
     411{
     412  ListIterator it = lst.begin();
     413  ListIterator e = lst.end();
     414  while(it != e) {
     415    append(*it);
     416    ++it;
     417  }
     418}
     419
     420void ListImp::prependList(const List& lst)
     421{
     422  ListIterator it = lst.end();
     423  ListIterator e = lst.begin();
     424  while(it != e) {
     425    --it;
     426    prepend(*it);
     427  }
     428}
     429
     430void ListImp::removeFirst()
     431{
     432  erase(hook->next);
     433}
     434
     435void ListImp::removeLast()
     436{
     437  erase(hook->prev);
     438}
     439
     440void ListImp::remove(const Value &obj)
     441{
     442  if (obj.isNull())
     443    return;
     444  ListNode *n = hook->next;
     445  while (n != hook) {
     446    if (n->member == obj.imp()) {
     447      erase(n);
     448      return;
     449    }
     450    n = n->next;
     451  }
     452}
     453
     454void ListImp::clear()
     455{
     456  ListNode *n = hook->next;
     457  while (n != hook) {
     458    n = n->next;
     459    delete n->prev;
     460  }
     461
     462  hook->next = hook;
     463  hook->prev = hook;
     464}
     465
     466ListImp *ListImp::copy() const
     467{
     468  ListImp* newList = new ListImp;
     469
     470  ListIterator e = end();
     471  ListIterator it = begin();
     472
     473  while(it != e) {
     474    newList->append(*it);
     475    ++it;
     476  }
     477
     478  //fprintf( stderr, "ListImp::copy returning newList=%p\n", newList );
     479  return newList;
     480}
     481
     482void ListImp::erase(ListNode *n)
     483{
     484  if (n != hook) {
     485    n->next->prev = n->prev;
     486    n->prev->next = n->next;
     487    delete n;
     488  }
     489}
     490
     491bool ListImp::isEmpty() const
     492{
     493  return (hook->prev == hook);
     494}
     495
     496int ListImp::size() const
     497{
     498  int s = 0;
     499  ListNode *node = hook;
     500  while ((node = node->next) != hook)
     501    s++;
     502
     503  return s;
     504}
     505
     506Value ListImp::at(int i) const
     507{
     508  if (i < 0 || i >= size())
     509    return Undefined();
     510
     511  ListIterator it = begin();
     512  int j = 0;
     513  while ((j++ < i))
     514    it++;
     515
     516  return *it;
     517}
     518
     519ListImp *ListImp::emptyList = 0L;
     520
     521ListImp *ListImp::empty()
     522{
     523  if (!emptyList)
     524    emptyList = new ListImp();
     525  return emptyList;
     526}
     527
  • trunk/JavaScriptCore/kjs/types.h

    r2256 r2741  
    108108    friend class ListIterator;
    109109  public:
    110     List();
     110    List(bool needsMarking = false);
     111    List(const List& l);
     112    List &operator=(const List& l);
     113     
     114    ~List();
    111115
    112116    /**
     
    190194    static void globalClear();
    191195#endif
    192 
     196    void mark();
     197    static void markEmptyList();
    193198  private:
    194199    List(ListImp *);
    195200    ListImp *imp() const { return (ListImp *)Value::imp(); }
    196     friend class ObjectImp;
     201    bool m_needsMarking;
    197202  };
    198203
Note: See TracChangeset for help on using the changeset viewer.