Ignore:
Timestamp:
Aug 14, 2002, 9:32:46 PM (23 years ago)
Author:
darin
Message:

Another pass of tweaks, including one bug fix.

  • kjs/array_object.cpp: (ArrayInstanceImp::ArrayInstanceImp): Use malloc, not new. (ArrayInstanceImp::get): Use a local variable so we don't rely on the optimizer to avoid indexing twice. (ArrayInstanceImp::hasProperty): Use a local variable, and also check against UndefinedImp::staticUndefined rather than doing type() != UndefinedType.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r1822 r1823  
    5252  , length(list.size())
    5353  , capacity(length)
    54   , storage(length ? new (ValueImp *)[length] : 0)
     54  , storage(length ? (ValueImp **)malloc(sizeof(ValueImp *) * length) : 0)
    5555{
    5656  ListIterator it = list.begin();
    57   const unsigned l = length;
     57  unsigned l = length;
    5858  for (unsigned i = 0; i < l; ++i) {
    5959    storage[i] = (it++).imp();
     
    6363ArrayInstanceImp::~ArrayInstanceImp()
    6464{
    65   free (storage);
     65  free(storage);
    6666}
    6767
     
    7474  unsigned index = propertyName.toULong(&ok);
    7575  if (ok) {
    76     if (index >= length || storage[index] == NULL)
     76    if (index >= length)
    7777      return Undefined();
    78     return Value(storage[index]);
     78    ValueImp *v = storage[index];
     79    return v ? Value(v) : Undefined();
    7980  }
    8081
     
    8485Value ArrayInstanceImp::get(ExecState *exec, unsigned index) const
    8586{
    86   if (index >= length || storage[index] == NULL)
     87  if (index >= length)
    8788    return Undefined();
    88   return Value(storage[index]);
     89  ValueImp *v = storage[index];
     90  return v ? Value(v) : Undefined();
    8991}
    9092
     
    124126    if (index >= length)
    125127      return false;
    126     return storage[index] != NULL && storage[index]->type() != UndefinedType;
     128    ValueImp *v = storage[index];
     129    return v && v != UndefinedImp::staticUndefined;
    127130  }
    128131 
     
    134137  if (index >= length)
    135138    return false;
    136   return storage[index] != NULL && storage[index]->type() != UndefinedType;
     139  ValueImp *v = storage[index];
     140  return v && v != UndefinedImp::staticUndefined;
    137141}
    138142
     
    147151    if (index >= length)
    148152      return true;
    149     storage[index] = NULL;
     153    storage[index] = 0;
    150154    return true;
    151155  }
     
    158162  if (index >= length)
    159163    return true;
    160   storage[index] = NULL;
     164  storage[index] = 0;
    161165  return true;
    162166}
     
    179183{
    180184  ObjectImp::mark();
    181   const unsigned l = length;
     185  unsigned l = length;
    182186  for (unsigned i = 0; i < l; ++i) {
    183187    ValueImp *imp = storage[i];
    184     if (imp != NULL && !imp->marked())
     188    if (imp && !imp->marked())
    185189      imp->mark();
    186190  }
Note: See TracChangeset for help on using the changeset viewer.