BoundedInlineVector: Add resize() method

Bug: webrtc:11391
Change-Id: I34d659d0e295617e9058393d4d1b510111a78b83
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/169520
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30664}
diff --git a/rtc_base/bounded_inline_vector.h b/rtc_base/bounded_inline_vector.h
index 6e8eb23..f8b7eb3 100644
--- a/rtc_base/bounded_inline_vector.h
+++ b/rtc_base/bounded_inline_vector.h
@@ -34,6 +34,7 @@
   static_assert(fixed_capacity > 0, "Capacity must be strictly positive");
 
  public:
+  using size_type = int;
   using value_type = T;
   using const_iterator = const T*;
 
@@ -108,6 +109,22 @@
   int size() const { return storage_.size; }
   constexpr int capacity() const { return fixed_capacity; }
 
+  // Resizes the BoundedInlineVector to the given size, which must not exceed
+  // its constant capacity. If the size is increased, the added elements are
+  // default constructed.
+  void resize(int new_size) {
+    RTC_DCHECK_GE(new_size, 0);
+    RTC_DCHECK_LE(new_size, fixed_capacity);
+    if (new_size > storage_.size) {
+      bounded_inline_vector_impl::DefaultInitializeElements(
+          storage_.data + storage_.size, new_size - storage_.size);
+    } else if (new_size < storage_.size) {
+      bounded_inline_vector_impl::DestroyElements(storage_.data + new_size,
+                                                  storage_.size - new_size);
+    }
+    storage_.size = new_size;
+  }
+
   const T* data() const { return storage_.data; }
   T* data() { return storage_.data; }