Changeset 31061 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Mar 14, 2008, 12:05:28 PM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Beth Dakin.


Fixed a few problems with Vector::shrinkCapacity that I noticed in testing.

  • wtf/Vector.h: (WTF::VectorBufferBase::deallocateBuffer): Clear our m_buffer pointer when we deallocate m_buffer, in case we're not asked to reallocate a new buffer. (Otherwise, we would use a stale m_buffer if we were asked to perform any operations after shrinkCapacity was called.)


(WTF::VectorBuffer::allocateBuffer): Made VectorBuffer with inline
capacity aware that calls to allocateBuffer might be shrinks, rather
than grows, so we shouldn't allocate a new buffer on the heap unless
our inline buffer is too small.


(WTF::::shrinkCapacity): Call resize() instead of just setting m_size,
so destructors run. Call resize before reallocating the buffer to make
sure that we still have access to the objects we need to destroy. Call
moveOverlapping instead of move, since a call to allocateBuffer on an
inline buffer may produce identical storage.

Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r31057 r31061  
     12008-03-14  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Beth Dakin.
     4       
     5        Fixed a few problems with Vector::shrinkCapacity that I noticed in testing.
     6
     7        * wtf/Vector.h:
     8        (WTF::VectorBufferBase::deallocateBuffer): Clear our m_buffer pointer
     9        when we deallocate m_buffer, in case we're not asked to reallocate a new
     10        buffer. (Otherwise, we would use a stale m_buffer if we were asked to
     11        perform any operations after shrinkCapacity was called.)
     12       
     13        (WTF::VectorBuffer::allocateBuffer): Made VectorBuffer with inline
     14        capacity aware that calls to allocateBuffer might be shrinks, rather
     15        than grows, so we shouldn't allocate a new buffer on the heap unless
     16        our inline buffer is too small.
     17       
     18        (WTF::::shrinkCapacity): Call resize() instead of just setting m_size,
     19        so destructors run. Call resize before reallocating the buffer to make
     20        sure that we still have access to the objects we need to destroy. Call
     21        moveOverlapping instead of move, since a call to allocateBuffer on an
     22        inline buffer may produce identical storage.
     23
    1242008-03-14  Alexey Proskuryakov  <[email protected]>
    225
     
    223246        * JavaScriptCore.vcproj/testkjs/testkjs.vcproj:
    224247
    225 2008-03-09  Jürg Billeter  <[email protected]>
     2482008-03-09  J¸rg Billeter  <[email protected]>
    226249
    227250        Reviewed by Alp Toker.
  • trunk/JavaScriptCore/wtf/Vector.h

    r31032 r31061  
    254254        void deallocateBuffer(T* bufferToDeallocate)
    255255        {
     256            if (m_buffer == bufferToDeallocate)
     257                m_buffer = 0;
    256258            fastFree(bufferToDeallocate);
    257259        }
     
    344346            : Base(inlineBuffer(), inlineCapacity)
    345347        {
    346             if (capacity > inlineCapacity)
    347                 allocateBuffer(capacity);
     348            allocateBuffer(capacity);
    348349        }
    349350
     
    353354        }
    354355
    355         using Base::allocateBuffer;
     356        void allocateBuffer(size_t newCapacity)
     357        {
     358            if (newCapacity > inlineCapacity)
     359                Base::allocateBuffer(newCapacity);
     360        }
    356361
    357362        void deallocateBuffer(T* bufferToDeallocate)
     
    666671            return;
    667672
     673        resize(min(m_size, newCapacity));
     674
    668675        T* oldBuffer = begin();
    669676        if (newCapacity > 0) {
    670677            T* oldEnd = end();
    671678            m_buffer.allocateBuffer(newCapacity);
    672             TypeOperations::move(oldBuffer, oldEnd, begin());
    673         }
    674         m_size = min(m_size, newCapacity);
     679            TypeOperations::moveOverlapping(oldBuffer, oldEnd, begin());
     680        }
     681
    675682        m_buffer.deallocateBuffer(oldBuffer);
    676683    }
Note: See TracChangeset for help on using the changeset viewer.