Changeset 16533 in webkit for trunk/JavaScriptCore/wtf


Ignore:
Timestamp:
Sep 22, 2006, 3:02:56 PM (19 years ago)
Author:
darin
Message:

Reviewed by Alice.

  • wtf/Vector.h: Add an append that takes a pointer and length. Generalize the existing Vector append to work on vectors with any value for inlineCapacity. Change the append algorithm so it doesn't check capacity each time through the loop.
File:
1 edited

Legend:

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

    r15002 r16533  
    385385        void clear() { resize(0); }
    386386
     387        template<typename U> void append(const U*, size_t);
    387388        template<typename U> void append(const U&);
    388         template<typename U> void append(const Vector<U>&);
     389        template<typename U, size_t c> void append(const Vector<U, c>&);
     390
    389391        template<typename U> void insert(size_t position, const U&);
     392
    390393        void remove(size_t position);
    391394
     
    539542    }
    540543
    541     // templatizing these is better than just letting the conversion happen implicitly,
     544    // Templatizing these is better than just letting the conversion happen implicitly,
    542545    // because for instance it allows a PassRefPtr to be appended to a RefPtr vector
    543546    // without refcount thrash.
     547
     548    template<typename T, size_t inlineCapacity> template<typename U>
     549    void Vector<T, inlineCapacity>::append(const U* data, size_t dataSize)
     550    {
     551        size_t newSize = m_size + dataSize;
     552        if (newSize > capacity())
     553            data = expandCapacity(newSize, data);
     554        T* dest = end();
     555        for (size_t i = 0; i < dataSize; ++i)
     556            new (&dest[i]) T(data[i]);
     557        m_size = newSize;
     558    }
    544559
    545560    template<typename T, size_t inlineCapacity> template<typename U>
     
    553568    }
    554569
    555     template<typename T, size_t inlineCapacity> template<typename U>
    556     inline void Vector<T, inlineCapacity>::append(const Vector<U>& val)
    557     {
    558         if (size() + val.size() >= capacity())
    559             expandCapacity(size() + val.size());
    560         for (unsigned i = 0; i < val.size(); i++)
    561             append(val[i]);
     570    template<typename T, size_t inlineCapacity> template<typename U, size_t c>
     571    inline void Vector<T, inlineCapacity>::append(const Vector<U, c>& val)
     572    {
     573        append(val.begin(), val.size());
    562574    }
    563575   
Note: See TracChangeset for help on using the changeset viewer.