Changeset 38285 in webkit for trunk/JavaScriptCore


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.
Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r38284 r38285  
     12008-11-10  Maciej Stachowiak  <[email protected]>
     2
     3        Reviewed by Antti Koivisto.
     4       
     5        - Make Vector::clear() release the Vector's memory (1MB savings on membuster)
     6        https://bugs.webkit.org/show_bug.cgi?id=22170
     7
     8        * wtf/Vector.h:
     9        (WTF::VectorBufferBase::deallocateBuffer): Set capacity to 0 as
     10        well as size, otherwise shrinking capacity to 0 can fail to reset
     11        the capacity and thus cause a future crash.
     12        (WTF::Vector::~Vector): Shrink size not capacity; we only need
     13        to call destructors, the buffer will be freed anyway.
     14        (WTF::Vector::clear): Change this to shrinkCapacity(0), not just shrink(0).
     15        (WTF::::shrinkCapacity): Use shrink() instead of resize() for case where
     16        the size is greater than the new capacity, to work with types that have no
     17        default constructor.
     18
    1192008-11-10  Cameron Zwarich  <[email protected]>
    220
  • 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.