OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 | 145 |
146 T* data() { return m_ptr; } | 146 T* data() { return m_ptr; } |
147 const T* data() const { return m_ptr; } | 147 const T* data() const { return m_ptr; } |
148 | 148 |
149 void swap(WebVector<T>& other) | 149 void swap(WebVector<T>& other) |
150 { | 150 { |
151 std::swap(m_ptr, other.m_ptr); | 151 std::swap(m_ptr, other.m_ptr); |
152 std::swap(m_size, other.m_size); | 152 std::swap(m_size, other.m_size); |
153 } | 153 } |
154 | 154 |
155 void shrink(size_t size) | |
tkent
2014/08/06 12:46:07
Why is this necessary?
WebVector has no rich opera
spartha
2014/08/06 13:31:09
The function pre-allocates the vector for efficien
| |
156 { | |
157 BLINK_ASSERT(size <= m_size); | |
158 for (size_t index = m_size - 1; index >= size; --index) | |
159 m_ptr[index].~T(); | |
160 m_size = size; | |
161 } | |
162 | |
155 private: | 163 private: |
156 void initialize(size_t size) | 164 void initialize(size_t size) |
157 { | 165 { |
158 validateSize(size); | 166 validateSize(size); |
159 m_size = size; | 167 m_size = size; |
160 if (!m_size) | 168 if (!m_size) |
161 m_ptr = 0; | 169 m_ptr = 0; |
162 else { | 170 else { |
163 m_ptr = static_cast<T*>(::operator new(sizeof(T) * m_size)); | 171 m_ptr = static_cast<T*>(::operator new(sizeof(T) * m_size)); |
164 for (size_t i = 0; i < m_size; ++i) | 172 for (size_t i = 0; i < m_size; ++i) |
(...skipping 28 matching lines...) Expand all Loading... | |
193 ::operator delete(m_ptr); | 201 ::operator delete(m_ptr); |
194 } | 202 } |
195 | 203 |
196 T* m_ptr; | 204 T* m_ptr; |
197 size_t m_size; | 205 size_t m_size; |
198 }; | 206 }; |
199 | 207 |
200 } // namespace blink | 208 } // namespace blink |
201 | 209 |
202 #endif | 210 #endif |
OLD | NEW |