Changeset 1822 in webkit for trunk/JavaScriptCore/kjs/array_object.cpp
- Timestamp:
- Aug 14, 2002, 8:19:38 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/array_object.cpp
r1821 r1822 44 44 , length(initialLength) 45 45 , capacity(length) 46 , storage(length ? new (ValueImp *)[length] : 0) 47 { 48 unsigned l = length; 49 for (unsigned i = 0; i < l; ++i) { 50 storage[i] = Undefined().imp(); 51 } 46 , storage(length ? (ValueImp **)calloc(length, sizeof(ValueImp *)) : 0) 47 { 52 48 } 53 49 … … 67 63 ArrayInstanceImp::~ArrayInstanceImp() 68 64 { 69 delete [] storage;65 free (storage); 70 66 } 71 67 … … 78 74 unsigned index = propertyName.toULong(&ok); 79 75 if (ok) { 80 if (index >= length )76 if (index >= length || storage[index] == NULL) 81 77 return Undefined(); 82 78 return Value(storage[index]); … … 88 84 Value ArrayInstanceImp::get(ExecState *exec, unsigned index) const 89 85 { 90 if (index >= length )86 if (index >= length || storage[index] == NULL) 91 87 return Undefined(); 92 88 return Value(storage[index]); … … 128 124 if (index >= length) 129 125 return false; 130 return storage[index] ->type() != UndefinedType;126 return storage[index] != NULL && storage[index]->type() != UndefinedType; 131 127 } 132 128 … … 138 134 if (index >= length) 139 135 return false; 140 return storage[index] ->type() != UndefinedType;136 return storage[index] != NULL && storage[index]->type() != UndefinedType; 141 137 } 142 138 … … 151 147 if (index >= length) 152 148 return true; 153 storage[index] = Undefined().imp();149 storage[index] = NULL; 154 150 return true; 155 151 } … … 162 158 if (index >= length) 163 159 return true; 164 storage[index] = Undefined().imp();160 storage[index] = NULL; 165 161 return true; 166 162 } … … 169 165 { 170 166 if (newLength < length) { 171 const unsigned l = length; 172 for (unsigned i = newLength; i < l; ++i) 173 storage[i] = Undefined().imp(); 167 memset(storage + newLength, 0, sizeof(ValueImp *) * (length - newLength)); 174 168 } 175 169 if (newLength > capacity) { 176 170 unsigned newCapacity = (newLength * 3 + 1) / 2; 177 ValueImp **newStorage = new (ValueImp *)[newCapacity]; 178 const unsigned l = length; 179 for (unsigned i = 0; i < l; ++i) 180 newStorage[i] = storage[i]; 181 for (unsigned i = l; i < newLength; i++) 182 newStorage[i] = Undefined().imp(); 183 delete [] storage; 184 storage = newStorage; 171 storage = (ValueImp **)realloc(storage, newCapacity * sizeof (ValueImp *)); 172 memset(storage + capacity, 0, sizeof(ValueImp *) * (newCapacity - capacity)); 185 173 capacity = newCapacity; 186 174 } … … 194 182 for (unsigned i = 0; i < l; ++i) { 195 183 ValueImp *imp = storage[i]; 196 if ( !imp->marked())184 if (imp != NULL && !imp->marked()) 197 185 imp->mark(); 198 186 }
Note:
See TracChangeset
for help on using the changeset viewer.