5 #ifndef V8_DETACHABLE_VECTOR_H_ 6 #define V8_DETACHABLE_VECTOR_H_ 12 #include "src/base/logging.h" 13 #include "src/base/macros.h" 27 void pop_back() { --size_; }
28 size_t capacity()
const {
return capacity_; }
29 size_t size()
const {
return size_; }
30 bool empty()
const {
return size_ == 0; }
32 static const size_t kMinimumCapacity;
33 static const size_t kDataOffset;
34 static const size_t kCapacityOffset;
35 static const size_t kSizeOffset;
38 void* data_ =
nullptr;
54 void push_back(
const T& value) {
55 if (size_ == capacity_) {
56 size_t new_capacity = std::max(kMinimumCapacity, 2 * capacity_);
60 data()[size_] = value;
72 T& at(
size_t i)
const {
76 T& back()
const {
return at(size_ - 1); }
77 T& front()
const {
return at(0); }
79 void shrink_to_fit() {
80 size_t new_capacity = std::max(size_, kMinimumCapacity);
81 if (new_capacity < capacity_ / 2) {
87 T* data()
const {
return static_cast<T*
>(data_); }
89 void Resize(
size_t new_capacity) {
90 DCHECK_LE(size_, new_capacity);
91 T* new_data_ =
new T[new_capacity];
93 std::copy(data(), data() + size_, new_data_);
97 capacity_ = new_capacity;
104 #endif // V8_DETACHABLE_VECTOR_H_