aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2018-01-24 08:01:53 -0800
committerGravatar Mark D. Roth <roth@google.com>2018-01-24 08:01:53 -0800
commit10f38f5a3374f418ef1249f38cb33e77e2e7ed46 (patch)
tree7f1543d921c537ba331e538ed2331d1158d1baf7 /src/core
parent9ab4d0c82699064efebd8a15eebf66e3db8bf256 (diff)
Initialize data members in a single place.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lib/gprpp/inlined_vector.h18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/core/lib/gprpp/inlined_vector.h b/src/core/lib/gprpp/inlined_vector.h
index 8044c682d1..2ced3d74b8 100644
--- a/src/core/lib/gprpp/inlined_vector.h
+++ b/src/core/lib/gprpp/inlined_vector.h
@@ -40,12 +40,12 @@ namespace grpc_core {
// ANY METHOD ADDED HERE MUST COMPLY WITH THE INTERFACE IN THE absl
// IMPLEMENTATION!
//
-// TODO(ctiller, nnoble, roth): Replace this with absl::InlinedVector
-// once we integrate absl into the gRPC build system in a usable way.
+// TODO(nnoble, roth): Replace this with absl::InlinedVector once we
+// integrate absl into the gRPC build system in a usable way.
template <typename T, size_t N>
class InlinedVector {
public:
- InlinedVector() {}
+ InlinedVector() { init_data(); }
~InlinedVector() { destroy_elements(); }
// For now, we do not support copying.
@@ -100,12 +100,16 @@ class InlinedVector {
void clear() {
destroy_elements();
+ init_data();
+ }
+
+ private:
+ void init_data() {
dynamic_ = nullptr;
size_ = 0;
dynamic_capacity_ = 0;
}
- private:
void destroy_elements() {
for (size_t i = 0; i < size_ && i < N; ++i) {
T& value = *reinterpret_cast<T*>(inline_ + i);
@@ -120,9 +124,9 @@ class InlinedVector {
}
typename std::aligned_storage<sizeof(T)>::type inline_[N];
- T* dynamic_ = nullptr;
- size_t size_ = 0;
- size_t dynamic_capacity_ = 0;
+ T* dynamic_;
+ size_t size_;
+ size_t dynamic_capacity_;
};
} // namespace grpc_core