Changeset 38285 in webkit for trunk/JavaScriptCore/wtf


Ignore:
Timestamp:
Nov 10, 2008, 7:51:24 PM (17 years ago)
Author:
[email protected]
Message:

2008-11-10 Maciej Stachowiak <[email protected]>

Reviewed by Antti Koivisto.


  • wtf/Vector.h: (WTF::VectorBufferBase::deallocateBuffer): Set capacity to 0 as well as size, otherwise shrinking capacity to 0 can fail to reset the capacity and thus cause a future crash. (WTF::Vector::~Vector): Shrink size not capacity; we only need to call destructors, the buffer will be freed anyway. (WTF::Vector::clear): Change this to shrinkCapacity(0), not just shrink(0). (WTF::::shrinkCapacity): Use shrink() instead of resize() for case where the size is greater than the new capacity, to work with types that have no default constructor.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/Vector.h

    r38173 r38285  
    280280        void deallocateBuffer(T* bufferToDeallocate)
    281281        {
    282             if (m_buffer == bufferToDeallocate)
     282            if (m_buffer == bufferToDeallocate) {
    283283                m_buffer = 0;
     284                m_capacity = 0;
     285            }
    284286            fastFree(bufferToDeallocate);
    285287        }
     
    443445        ~Vector()
    444446        {
    445             clear();
     447            if (m_size) shrink(0);
    446448        }
    447449
     
    494496        void shrinkCapacity(size_t newCapacity);
    495497
    496         void clear() { if (m_size) shrink(0); }
     498        void clear() { shrinkCapacity(0); }
    497499
    498500        template<typename U> void append(const U*, size_t);
     
    726728            return;
    727729
    728         resize(min(m_size, newCapacity));
     730        if (newCapacity < size())
     731            shrink(newCapacity);
    729732
    730733        T* oldBuffer = begin();
Note: See TracChangeset for help on using the changeset viewer.