Changeset 17200 in webkit for trunk/JavaScriptCore/wtf/Vector.h


Ignore:
Timestamp:
Oct 21, 2006, 6:55:53 PM (19 years ago)
Author:
darin
Message:

Reviewed by Anders.

  • wtf/Vector.h: (WTF::VectorBuffer::swap): Added. (WTF::Vector::swap): Added. (WTF::swap): Added overload that takes two Vector objects.
File:
1 edited

Legend:

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

    r17127 r17200  
    8383        static void initialize(T* begin, T* end)
    8484        {
    85             memset(begin, 0, reinterpret_cast<char *>(end) - reinterpret_cast<char *>(begin));
     85            memset(begin, 0, reinterpret_cast<char*>(end) - reinterpret_cast<char*>(begin));
    8686        }
    8787    };
     
    123123        static void move(const T* src, const T* srcEnd, T* dst)
    124124        {
    125             memcpy(dst, src, reinterpret_cast<const char *>(srcEnd) - reinterpret_cast<const char *>(src));
     125            memcpy(dst, src, reinterpret_cast<const char*>(srcEnd) - reinterpret_cast<const char*>(src));
    126126        }
    127127        static void moveOverlapping(const T* src, const T* srcEnd, T* dst)
    128128        {
    129             memmove(dst, src, reinterpret_cast<const char *>(srcEnd) - reinterpret_cast<const char *>(src));
     129            memmove(dst, src, reinterpret_cast<const char*>(srcEnd) - reinterpret_cast<const char*>(src));
    130130        }
    131131    };
     
    152152        static void uninitializedCopy(const T* src, const T* srcEnd, T* dst)
    153153        {
    154             memcpy(dst, src, reinterpret_cast<const char *>(srcEnd) - reinterpret_cast<const char *>(src));
     154            memcpy(dst, src, reinterpret_cast<const char*>(srcEnd) - reinterpret_cast<const char*>(src));
    155155        }
    156156    };
     
    256256        const T* buffer() const { return m_buffer; }
    257257        size_t capacity() const { return m_capacity; }
     258
     259        void swap(VectorBuffer<T, 0>& other)
     260        {
     261            std::swap(m_capacity, other.m_capacity);
     262            std::swap(m_buffer, other.m_buffer);
     263        }
    258264
    259265        T* releaseBuffer()
     
    318324        }
    319325
     326        void swap(VectorBuffer<T, inlineCapacity>&);
     327
    320328    private:
    321329        static const size_t m_inlineBufferSize = inlineCapacity * sizeof(T);
    322330        T* inlineBuffer() { return reinterpret_cast<T*>(&m_inlineBuffer); }
    323331
     332        // FIXME: Nothing guarantees this buffer is appropriately aligned to hold objects of type T.
    324333        char m_inlineBuffer[m_inlineBufferSize];
    325334    };
     
    428437        }
    429438
    430         void fill(const T& val, size_t size);
     439        void fill(const T&, size_t);
    431440        void fill(const T& val) { fill(val, size()); }
    432441
    433442        T* releaseBuffer();
     443
     444        void swap(Vector<T, inlineCapacity>& other)
     445        {
     446            std::swap(m_size, other.m_size);
     447            m_impl.swap(other.m_impl);
     448        }
    434449
    435450    private:
     
    646661    }
    647662
     663    template<typename T, size_t inlineCapacity>
     664    inline void swap(Vector<T, inlineCapacity>& a, Vector<T, inlineCapacity>& b)
     665    {
     666        a.swap(b);
     667    }
     668
    648669} // namespace WTF
    649670
Note: See TracChangeset for help on using the changeset viewer.