19 #ifndef GRPC_CORE_LIB_GPRPP_INLINED_VECTOR_H 20 #define GRPC_CORE_LIB_GPRPP_INLINED_VECTOR_H 30 #include "absl/container/inlined_vector.h" 37 template <
typename T,
size_t N,
typename A = std::allocator<T>>
38 using InlinedVector = absl::InlinedVector<T, N, A>;
59 template <
typename T,
size_t N>
94 return dynamic_ !=
nullptr ? dynamic_ :
reinterpret_cast<T*
>(inline_);
98 return dynamic_ !=
nullptr ? dynamic_ :
reinterpret_cast<const T*
>(inline_);
102 assert(offset < size_);
103 return data()[offset];
107 assert(offset < size_);
108 return data()[offset];
112 if (size_ != other.size_)
return false;
113 for (
size_t i = 0; i < size_; ++i) {
116 if (!(
data()[i] == other.
data()[i]))
return false;
122 return !(*
this == other);
128 std::alignment_of<T>::value == 0
131 sizeof(T) *
capacity, std::alignment_of<T>::value));
132 move_elements(
data(), new_dynamic, size_);
134 dynamic_ = new_dynamic;
141 while (new_size < size_)
pop_back();
144 template <
typename... Args>
146 if (size_ == capacity_) {
149 new (&(
data()[size_])) T(std::forward<Args>(args)...);
160 T& value =
data()[s - 1];
165 size_t size()
const {
return size_; }
166 bool empty()
const {
return size_ == 0; }
178 if (v.dynamic_ !=
nullptr) {
182 for (
size_t i = 0; i < v.size_; ++i) {
183 new (&(
data()[i])) T(v[i]);
187 capacity_ = v.capacity_;
193 if (v.dynamic_ !=
nullptr) {
194 dynamic_ = v.dynamic_;
196 move_elements(v.data(),
data(), v.size_);
200 capacity_ = v.capacity_;
205 static void move_elements(T* src, T* dst,
size_t num_elements) {
206 for (
size_t i = 0; i < num_elements; ++i) {
207 new (&dst[i]) T(std::move(src[i]));
218 void destroy_elements() {
219 for (
size_t i = 0; i < size_; ++i) {
220 T& value =
data()[i];
226 void free_dynamic() {
227 if (dynamic_ !=
nullptr) {
228 if (std::alignment_of<T>::value == 0) {
236 typename std::aligned_storage<sizeof(T)>::type inline_[N];
InlinedVector(const InlinedVector &v)
Definition: inlined_vector.h:66
void reserve(size_t capacity)
Definition: inlined_vector.h:125
GPRAPI void gpr_free(void *ptr)
free
T & operator[](size_t offset)
Definition: inlined_vector.h:101
Definition: inlined_vector.h:60
T * data()
Definition: inlined_vector.h:93
InlinedVector()
Definition: inlined_vector.h:62
bool operator!=(const InlinedVector &other) const
Definition: inlined_vector.h:121
InlinedVector(InlinedVector &&v)
Definition: inlined_vector.h:80
Internal thread interface.
Definition: backoff.h:26
InlinedVector & operator=(InlinedVector &&v)
Definition: inlined_vector.h:85
void pop_back()
Definition: inlined_vector.h:157
InlinedVector & operator=(const InlinedVector &v)
Definition: inlined_vector.h:71
const T & operator[](size_t offset) const
Definition: inlined_vector.h:106
GPRAPI void gpr_free_aligned(void *ptr)
free memory allocated by gpr_malloc_aligned
~InlinedVector()
Definition: inlined_vector.h:63
bool empty() const
Definition: inlined_vector.h:166
GPRAPI void * gpr_malloc_aligned(size_t size, size_t alignment)
aligned malloc, never returns NULL, will align to alignment, which must be a power of 2...
size_t size() const
Definition: inlined_vector.h:165
size_t capacity() const
Definition: inlined_vector.h:168
void push_back(const T &value)
Definition: inlined_vector.h:153
bool operator==(const InlinedVector &other) const
Definition: inlined_vector.h:111
GPRAPI void * gpr_malloc(size_t size)
malloc.
void push_back(T &&value)
Definition: inlined_vector.h:155
void clear()
Definition: inlined_vector.h:170
void resize(size_t new_size)
Definition: inlined_vector.h:139
const T * data() const
Definition: inlined_vector.h:97
void emplace_back(Args &&... args)
Definition: inlined_vector.h:145