Changeset 64588 in webkit for trunk/JavaScriptCore/runtime/JSArray.cpp
- Timestamp:
- Aug 3, 2010, 2:29:32 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSArray.cpp
r64320 r64588 133 133 134 134 ArrayStorage* storage = static_cast<ArrayStorage*>(fastZeroedMalloc(storageSize(initialCapacity))); 135 storage->m_allocBase = storage; 135 136 m_indexBias = 0; 136 137 setArrayStorage(storage); … … 138 139 139 140 checkConsistency(); 141 142 Heap::heap(this)->reportExtraMemoryCost(storageSize(0)); 140 143 } 141 144 … … 150 153 151 154 ArrayStorage* storage = static_cast<ArrayStorage*>(fastMalloc(storageSize(initialCapacity))); 155 storage->m_allocBase = storage; 152 156 storage->m_length = initialLength; 153 157 m_indexBias = 0; … … 177 181 checkConsistency(); 178 182 179 Heap::heap(this)->reportExtraMemoryCost( initialCapacity * sizeof(JSValue));183 Heap::heap(this)->reportExtraMemoryCost(storageSize(initialCapacity)); 180 184 } 181 185 … … 186 190 187 191 ArrayStorage* storage = static_cast<ArrayStorage*>(fastMalloc(storageSize(initialCapacity))); 192 storage->m_allocBase = storage; 188 193 m_indexBias = 0; 189 194 storage->m_length = initialCapacity; … … 216 221 ArrayStorage* storage = arrayStorage(); 217 222 delete storage->m_sparseValueMap; 218 char* realStorage = reinterpret_cast<char*>(storage) - (m_indexBias * sizeof(JSValue)); 219 fastFree(realStorage); 223 fastFree(storage->m_allocBase); 220 224 } 221 225 … … 417 421 } 418 422 419 int baseBias = m_indexBias * sizeof(JSValue); 420 char* baseStorage = reinterpret_cast<char*>(storage - baseBias); 423 void* baseStorage = storage->m_allocBase; 421 424 422 425 if (!tryFastRealloc(baseStorage, storageSize(newVectorLength + m_indexBias)).getValue(baseStorage)) { … … 425 428 } 426 429 427 storage = reinterpret_cast<ArrayStorage*>(baseStorage + baseBias); 430 storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue)); 431 storage->m_allocBase = baseStorage; 428 432 setArrayStorage(storage); 429 433 … … 568 572 ASSERT(newLength <= MAX_STORAGE_VECTOR_INDEX); 569 573 unsigned newVectorLength = getNewVectorLength(newLength); 570 int baseBias = m_indexBias * sizeof(JSValue); 571 char* baseStorage = reinterpret_cast<char*>(storage) - baseBias; 574 void* baseStorage = storage->m_allocBase; 572 575 573 576 if (!tryFastRealloc(baseStorage, storageSize(newVectorLength + m_indexBias)).getValue(baseStorage)) 574 577 return false; 575 576 storage = reinterpret_cast<ArrayStorage*>(baseStorage + baseBias); 578 579 storage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(baseStorage) + m_indexBias * sizeof(JSValue)); 580 storage->m_allocBase = baseStorage; 577 581 setArrayStorage(storage); 578 582 … … 600 604 ASSERT(newLength <= MAX_STORAGE_VECTOR_INDEX); 601 605 unsigned newVectorLength = getNewVectorLength(newLength); 602 char* baseStorage = reinterpret_cast<char*>(storage) - (m_indexBias * sizeof(JSValue)); 603 604 char* newBaseStorage = reinterpret_cast<char*>(fastMalloc(storageSize(newVectorLength + m_indexBias))); 606 607 void* newBaseStorage = fastMalloc(storageSize(newVectorLength + m_indexBias)); 605 608 if (!newBaseStorage) 606 609 return false; 607 610 608 611 m_indexBias += newVectorLength - newLength; 609 int newStorageOffset = m_indexBias * sizeof(JSValue); 610 611 newStorage = reinterpret_cast<ArrayStorage*>(newBaseStorage + newStorageOffset); 612 612 613 newStorage = reinterpret_cast<ArrayStorage*>(static_cast<char*>(newBaseStorage) + m_indexBias * sizeof(JSValue)); 614 613 615 memcpy(newStorage, storage, storageSize(0)); 614 616 memcpy(&newStorage->m_vector[newLength - m_vectorLength], &storage->m_vector[0], storage->m_length * sizeof(JSValue)); 615 617 618 newStorage->m_allocBase = newBaseStorage; 616 619 m_vectorLength = newLength; 617 620 618 fastFree( baseStorage);621 fastFree(storage->m_allocBase); 619 622 620 623 setArrayStorage(newStorage);
Note:
See TracChangeset
for help on using the changeset viewer.