| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #ifndef TerminatedArrayBuilder_h | 4 #ifndef TerminatedArrayBuilder_h |
| 5 #define TerminatedArrayBuilder_h | 5 #define TerminatedArrayBuilder_h |
| 6 | 6 |
| 7 #include "wtf/OwnPtr.h" | 7 #include "wtf/OwnPtr.h" |
| 8 | 8 |
| 9 namespace WTF { | 9 namespace WTF { |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 ASSERT(m_array->at(m_count - 1).isLastInArray()); | 36 ASSERT(m_array->at(m_count - 1).isLastInArray()); |
| 37 m_capacity += count; | 37 m_capacity += count; |
| 38 m_array = ArrayType<T>::Allocator::resize(m_array.release(), m_capac
ity); | 38 m_array = ArrayType<T>::Allocator::resize(m_array.release(), m_capac
ity); |
| 39 m_array->at(m_count - 1).setLastInArray(false); | 39 m_array->at(m_count - 1).setLastInArray(false); |
| 40 } | 40 } |
| 41 m_array->at(m_capacity - 1).setLastInArray(true); | 41 m_array->at(m_capacity - 1).setLastInArray(true); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void append(const T& item) | 44 void append(const T& item) |
| 45 { | 45 { |
| 46 CHECK_LT(m_count, m_capacity); | 46 RELEASE_ASSERT(m_count < m_capacity); |
| 47 ASSERT(!item.isLastInArray()); | 47 ASSERT(!item.isLastInArray()); |
| 48 m_array->at(m_count++) = item; | 48 m_array->at(m_count++) = item; |
| 49 if (m_count == m_capacity) | 49 if (m_count == m_capacity) |
| 50 m_array->at(m_capacity - 1).setLastInArray(true); | 50 m_array->at(m_capacity - 1).setLastInArray(true); |
| 51 } | 51 } |
| 52 | 52 |
| 53 typename ArrayType<T>::Allocator::PassPtr release() | 53 typename ArrayType<T>::Allocator::PassPtr release() |
| 54 { | 54 { |
| 55 CHECK_EQ(m_count, m_capacity); | 55 RELEASE_ASSERT(m_count == m_capacity); |
| 56 assertValid(); | 56 assertValid(); |
| 57 return m_array.release(); | 57 return m_array.release(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 #if ENABLE(ASSERT) | 61 #if ENABLE(ASSERT) |
| 62 void assertValid() | 62 void assertValid() |
| 63 { | 63 { |
| 64 for (size_t i = 0; i < m_count; ++i) { | 64 for (size_t i = 0; i < m_count; ++i) { |
| 65 bool isLastInArray = (i + 1 == m_count); | 65 bool isLastInArray = (i + 1 == m_count); |
| 66 ASSERT(m_array->at(i).isLastInArray() == isLastInArray); | 66 ASSERT(m_array->at(i).isLastInArray() == isLastInArray); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 #else | 69 #else |
| 70 void assertValid() { } | 70 void assertValid() { } |
| 71 #endif | 71 #endif |
| 72 | 72 |
| 73 typename ArrayType<T>::Allocator::Ptr m_array; | 73 typename ArrayType<T>::Allocator::Ptr m_array; |
| 74 size_t m_count; | 74 size_t m_count; |
| 75 size_t m_capacity; | 75 size_t m_capacity; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 } // namespace WTF | 78 } // namespace WTF |
| 79 | 79 |
| 80 using WTF::TerminatedArrayBuilder; | 80 using WTF::TerminatedArrayBuilder; |
| 81 | 81 |
| 82 #endif // TerminatedArrayBuilder_h | 82 #endif // TerminatedArrayBuilder_h |
| OLD | NEW |