Changeset 30538 in webkit for trunk/JavaScriptCore/wtf/Vector.h
- Timestamp:
- Feb 23, 2008, 9:19:27 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/Vector.h
r29470 r30538 25 25 #include "Assertions.h" 26 26 #include "FastMalloc.h" 27 #include "Noncopyable.h" 27 28 #include "VectorTraits.h" 28 29 #include <limits> … … 241 242 242 243 template<typename T> 243 class VectorBufferBase {244 class VectorBufferBase : Noncopyable { 244 245 public: 245 246 void allocateBuffer(size_t newCapacity) … … 386 387 class Vector { 387 388 private: 388 typedef VectorBuffer<T, inlineCapacity> Impl;389 typedef VectorBuffer<T, inlineCapacity> Buffer; 389 390 typedef VectorTypeOperations<T> TypeOperations; 390 391 … … 402 403 explicit Vector(size_t size) 403 404 : m_size(size) 404 , m_ impl(size)405 , m_buffer(size) 405 406 { 406 407 TypeOperations::initialize(begin(), end()); … … 421 422 422 423 size_t size() const { return m_size; } 423 size_t capacity() const { return m_ impl.capacity(); }424 size_t capacity() const { return m_buffer.capacity(); } 424 425 bool isEmpty() const { return !size(); } 425 426 … … 427 428 { 428 429 ASSERT(i < size()); 429 return m_ impl.buffer()[i];430 return m_buffer.buffer()[i]; 430 431 } 431 432 const T& at(size_t i) const 432 433 { 433 434 ASSERT(i < size()); 434 return m_ impl.buffer()[i];435 return m_buffer.buffer()[i]; 435 436 } 436 437 … … 438 439 const T& operator[](size_t i) const { return at(i); } 439 440 440 T* data() { return m_ impl.buffer(); }441 const T* data() const { return m_ impl.buffer(); }441 T* data() { return m_buffer.buffer(); } 442 const T* data() const { return m_buffer.buffer(); } 442 443 443 444 iterator begin() { return data(); } … … 481 482 Vector(size_t size, const T& val) 482 483 : m_size(size) 483 , m_ impl(size)484 , m_buffer(size) 484 485 { 485 486 TypeOperations::uninitializedFill(begin(), end(), val); … … 496 497 { 497 498 std::swap(m_size, other.m_size); 498 m_ impl.swap(other.m_impl);499 m_buffer.swap(other.m_buffer); 499 500 } 500 501 … … 505 506 506 507 size_t m_size; 507 Impl m_impl;508 Buffer m_buffer; 508 509 }; 509 510 … … 511 512 Vector<T, inlineCapacity>::Vector(const Vector& other) 512 513 : m_size(other.size()) 513 , m_ impl(other.capacity())514 , m_buffer(other.capacity()) 514 515 { 515 516 TypeOperations::uninitializedCopy(other.begin(), other.end(), begin()); … … 520 521 Vector<T, inlineCapacity>::Vector(const Vector<T, otherCapacity>& other) 521 522 : m_size(other.size()) 522 , m_ impl(other.capacity())523 , m_buffer(other.capacity()) 523 524 { 524 525 TypeOperations::uninitializedCopy(other.begin(), other.end(), begin()); … … 653 654 T* oldBuffer = begin(); 654 655 T* oldEnd = end(); 655 m_ impl.allocateBuffer(newCapacity);656 m_buffer.allocateBuffer(newCapacity); 656 657 TypeOperations::move(oldBuffer, oldEnd, begin()); 657 m_ impl.deallocateBuffer(oldBuffer);658 m_buffer.deallocateBuffer(oldBuffer); 658 659 } 659 660 … … 681 682 ptr = expandCapacity(size() + 1, ptr); 682 683 684 #if COMPILER(MSVC7) 683 685 // FIXME: MSVC7 generates compilation errors when trying to assign 684 686 // a pointer to a Vector of its base class (i.e. can't downcast). So far 685 687 // I've been unable to determine any logical reason for this, so I can 686 // only assume it is a bug with the compiler. Casting is very bad 687 // however because it subverts implicit conversions, so a better 688 // solution is direly needed. 689 #if COMPILER(MSVC7) 688 // only assume it is a bug with the compiler. Casting is a bad solution, 689 // however, because it subverts implicit conversions, so a better 690 // one is needed. 690 691 new (end()) T(static_cast<T>(*ptr)); 691 692 #else … … 777 778 inline T* Vector<T, inlineCapacity>::releaseBuffer() 778 779 { 779 T* buffer = m_ impl.releaseBuffer();780 T* buffer = m_buffer.releaseBuffer(); 780 781 if (inlineCapacity && !buffer && m_size) { 781 782 // If the vector had some data, but no buffer to release,
Note:
See TracChangeset
for help on using the changeset viewer.