Ignore:
Timestamp:
Jan 28, 2003, 12:50:56 PM (22 years ago)
Author:
darin
Message:

Reviewed by Maciej.

  • fixed 3144918 -- Can't drill down multiple levels of categories when selling on ebay if first item in list is chosen

The bug was caused by having array values in the property map past the storageLength cutoff
in an array object; those values would not be seen when you do a get.

  • kjs/array_object.cpp: (ArrayInstanceImp::put): Implement a new rule for resizing the storage that is independent of the length. The old rule would sometimes make the storage very big if you added two elements in a row that both had large, but consecutive indexes. This eliminates any cases where we make sparse entries in the property map below the sparse array cutoff. (ArrayInstanceImp::resizeStorage): Don't ever make storage size bigger than the cutoff unless the caller specifically requests it. (ArrayInstanceImp::setLength): Change this so it only makes the storage smaller, never larger. We will actually enlarge the storage when putting elements in.
File:
1 edited

Legend:

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

    r3373 r3478  
    113113  unsigned index = propertyName.toULong(&ok);
    114114  if (ok) {
    115     if (length <= index)
    116       setLength(index + 1, exec);
    117     if (index < storageLength) {
    118       storage[index] = value.imp();
    119       return;
    120     }
     115    put(exec, index, value, attr);
     116    return;
    121117  }
    122118 
     
    126122void ArrayInstanceImp::put(ExecState *exec, unsigned index, const Value &value, int attr)
    127123{
    128   if (length <= index)
    129     setLength(index + 1, exec);
     124  if (index < sparseArrayCutoff && index >= storageLength) {
     125    resizeStorage(index + 1);
     126  }
     127
     128  if (index >= length) {
     129    length = index + 1;
     130  }
     131
    130132  if (index < storageLength) {
    131133    storage[index] = value.imp();
     
    133135  }
    134136 
     137  assert(index >= sparseArrayCutoff);
    135138  ObjectImp::put(exec, Identifier::from(index), value, attr);
    136139}
     
    214217}
    215218
    216 
    217219void ArrayInstanceImp::resizeStorage(unsigned newLength)
    218220{
     
    221223    }
    222224    if (newLength > capacity) {
    223       unsigned newCapacity = (newLength * 3 + 1) / 2;
     225      unsigned newCapacity;
     226      if (newLength > sparseArrayCutoff) {
     227        newCapacity = newLength;
     228      } else {
     229        newCapacity = (newLength * 3 + 1) / 2;
     230        if (newCapacity > sparseArrayCutoff) {
     231          newCapacity = sparseArrayCutoff;
     232        }
     233      }
    224234      storage = (ValueImp **)realloc(storage, newCapacity * sizeof (ValueImp *));
    225235      memset(storage + capacity, 0, sizeof(ValueImp *) * (newCapacity - capacity));
     
    231241void ArrayInstanceImp::setLength(unsigned newLength, ExecState *exec)
    232242{
    233   if (newLength <= MAX(sparseArrayCutoff,storageLength) || newLength == length + 1) {
     243  if (newLength <= storageLength) {
    234244    resizeStorage(newLength);
    235245  }
Note: See TracChangeset for help on using the changeset viewer.