Changeset 31032 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Mar 13, 2008, 11:32:07 AM (17 years ago)
Author:
Beth Dakin
Message:

Reviewed by Geoff.

Adding new functionality to Vector. Currently all of the shrink and
resize functions on Vector only shrink the size of the Vector, not
the capacity. For the Vector to take up as little memory as
possible, though, it is necessary to be able to shrink the capacity
as well. So this patch adds that functionality.

I need this for a speed up I am working on, and Geoff wants to use
it in a speed up he is working on also, so he asked me to commit it
now.

  • wtf/Vector.h: (WTF::VectorBufferBase::allocateBuffer): (WTF::::shrinkCapacity):
Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r31030 r31032  
     12008-03-13  Beth Dakin  <[email protected]>
     2
     3        Reviewed by Geoff.
     4
     5        Adding new functionality to Vector. Currently all of the shrink and
     6        resize functions on Vector only shrink the size of the Vector, not
     7        the capacity. For the Vector to take up as little memory as
     8        possible, though, it is necessary to be able to shrink the capacity
     9        as well. So this patch adds that functionality.
     10
     11        I need this for a speed up I am working on, and Geoff wants to use
     12        it in a speed up he is working on also, so he asked me to commit it
     13        now.
     14
     15        * wtf/Vector.h:
     16        (WTF::VectorBufferBase::allocateBuffer):
     17        (WTF::::shrinkCapacity):
     18
    1192008-03-13  Simon Hausmann  <[email protected]>
    220
  • trunk/JavaScriptCore/wtf/Vector.h

    r30593 r31032  
    246246        void allocateBuffer(size_t newCapacity)
    247247        {
    248             ASSERT(newCapacity >= m_capacity);
    249248            m_capacity = newCapacity;
    250249            if (newCapacity > std::numeric_limits<size_t>::max() / sizeof(T))
     
    456455        void resize(size_t size);
    457456        void reserveCapacity(size_t newCapacity);
     457        void shrinkCapacity(size_t newCapacity);
    458458
    459459        void clear() { if (m_size) shrink(0); }
     
    657657        m_buffer.allocateBuffer(newCapacity);
    658658        TypeOperations::move(oldBuffer, oldEnd, begin());
     659        m_buffer.deallocateBuffer(oldBuffer);
     660    }
     661   
     662    template<typename T, size_t inlineCapacity>
     663    void Vector<T, inlineCapacity>::shrinkCapacity(size_t newCapacity)
     664    {
     665        if (newCapacity >= capacity())
     666            return;
     667
     668        T* oldBuffer = begin();
     669        if (newCapacity > 0) {
     670            T* oldEnd = end();
     671            m_buffer.allocateBuffer(newCapacity);
     672            TypeOperations::move(oldBuffer, oldEnd, begin());
     673        }
     674        m_size = min(m_size, newCapacity);
    659675        m_buffer.deallocateBuffer(oldBuffer);
    660676    }
Note: See TracChangeset for help on using the changeset viewer.