Rename GrowableArray to Vector
I'm not sure why we called it something so long. This is just a worse
version of std::vector. (Once we decide we stop believing in malloc
failures, we should just switch to the real std::vector.)
Change-Id: Iec9b1010a15316e6760758ba264897c13e3fdbac
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/71787
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/ssl/internal.h b/ssl/internal.h
index 718908b..43ea1c2 100644
--- a/ssl/internal.h
+++ b/ssl/internal.h
@@ -336,22 +336,21 @@
size_t size_ = 0;
};
-// GrowableArray<T> is an array that owns elements of |T|, backed by an
-// Array<T>. When necessary, pushing will automatically trigger a resize.
+// Vector<T> is a resizable array of elements of |T|.
//
// Note, for simplicity, this class currently differs from |std::vector| in that
// |T| must be efficiently default-constructible. Allocated elements beyond the
// end of the array are constructed and destructed.
template <typename T>
-class GrowableArray {
+class Vector {
public:
- GrowableArray() = default;
- GrowableArray(const GrowableArray &) = delete;
- GrowableArray(GrowableArray &&other) { *this = std::move(other); }
- ~GrowableArray() {}
+ Vector() = default;
+ Vector(const Vector &) = delete;
+ Vector(Vector &&other) { *this = std::move(other); }
+ ~Vector() {}
- GrowableArray &operator=(const GrowableArray &) = delete;
- GrowableArray &operator=(GrowableArray &&other) {
+ Vector &operator=(const Vector &) = delete;
+ Vector &operator=(Vector &&other) {
size_ = other.size_;
other.size_ = 0;
array_ = std::move(other.array_);
@@ -425,10 +424,10 @@
return true;
}
- // |size_| is the number of elements stored in this GrowableArray.
+ // |size_| is the number of elements stored in this Vector.
size_t size_ = 0;
// |array_| is the backing array. Note that |array_.size()| is this
- // GrowableArray's current capacity and that |size_ <= array_.size()|.
+ // Vector's current capacity and that |size_ <= array_.size()|.
Array<T> array_;
// |kDefaultSize| is the default initial size of the backing array.
static constexpr size_t kDefaultSize = 16;
@@ -2533,7 +2532,7 @@
// credentials is the list of credentials to select between. Elements of this
// array immutable.
- GrowableArray<UniquePtr<SSL_CREDENTIAL>> credentials;
+ Vector<UniquePtr<SSL_CREDENTIAL>> credentials;
// legacy_credential is the credential configured by the legacy
// non-credential-based APIs. If IsComplete() returns true, it is appended to
@@ -3213,7 +3212,7 @@
// alps_configs contains the list of supported protocols to use with ALPS,
// along with their corresponding ALPS values.
- GrowableArray<ALPSConfig> alps_configs;
+ Vector<ALPSConfig> alps_configs;
// Contains the QUIC transport params that this endpoint will send.
Array<uint8_t> quic_transport_params;
@@ -3816,7 +3815,7 @@
bssl::UniquePtr<STACK_OF(SRTP_PROTECTION_PROFILE)> srtp_profiles;
// Defined compression algorithms for certificates.
- bssl::GrowableArray<bssl::CertCompressionAlg> cert_compression_algs;
+ bssl::Vector<bssl::CertCompressionAlg> cert_compression_algs;
// Supported group values inherited by SSL structure
bssl::Array<uint16_t> supported_group_list;
@@ -4157,7 +4156,7 @@
struct ssl_ech_keys_st : public bssl::RefCounted<ssl_ech_keys_st> {
ssl_ech_keys_st() : RefCounted(CheckSubClass()) {}
- bssl::GrowableArray<bssl::UniquePtr<bssl::ECHServerConfig>> configs;
+ bssl::Vector<bssl::UniquePtr<bssl::ECHServerConfig>> configs;
private:
friend RefCounted;
diff --git a/ssl/ssl_test.cc b/ssl/ssl_test.cc
index 17fe5c6..b552885 100644
--- a/ssl/ssl_test.cc
+++ b/ssl/ssl_test.cc
@@ -567,69 +567,69 @@
return true;
}
-TEST(GrowableArrayTest, Resize) {
- GrowableArray<size_t> array;
- ASSERT_TRUE(array.empty());
- EXPECT_EQ(array.size(), 0u);
+TEST(VectorTest, Resize) {
+ Vector<size_t> vec;
+ ASSERT_TRUE(vec.empty());
+ EXPECT_EQ(vec.size(), 0u);
- ASSERT_TRUE(array.Push(42));
- ASSERT_TRUE(!array.empty());
- EXPECT_EQ(array.size(), 1u);
+ ASSERT_TRUE(vec.Push(42));
+ ASSERT_TRUE(!vec.empty());
+ EXPECT_EQ(vec.size(), 1u);
// Force a resize operation to occur
for (size_t i = 0; i < 16; i++) {
- ASSERT_TRUE(array.Push(i + 1));
+ ASSERT_TRUE(vec.Push(i + 1));
}
- EXPECT_EQ(array.size(), 17u);
+ EXPECT_EQ(vec.size(), 17u);
- // Verify that expected values are still contained in array
- for (size_t i = 0; i < array.size(); i++) {
- EXPECT_EQ(array[i], i == 0 ? 42 : i);
+ // Verify that expected values are still contained in vec
+ for (size_t i = 0; i < vec.size(); i++) {
+ EXPECT_EQ(vec[i], i == 0 ? 42 : i);
}
}
-TEST(GrowableArrayTest, MoveConstructor) {
- GrowableArray<size_t> array;
+TEST(VectorTest, MoveConstructor) {
+ Vector<size_t> vec;
for (size_t i = 0; i < 100; i++) {
- ASSERT_TRUE(array.Push(i));
+ ASSERT_TRUE(vec.Push(i));
}
- GrowableArray<size_t> array_moved(std::move(array));
+ Vector<size_t> vec_moved(std::move(vec));
for (size_t i = 0; i < 100; i++) {
- EXPECT_EQ(array_moved[i], i);
+ EXPECT_EQ(vec_moved[i], i);
}
}
-TEST(GrowableArrayTest, GrowableArrayContainingGrowableArrays) {
- // Representative example of a struct that contains a GrowableArray.
+TEST(VectorTest, VectorContainingVectors) {
+ // Representative example of a struct that contains a Vector.
struct TagAndArray {
size_t tag;
- GrowableArray<size_t> array;
+ Vector<size_t> vec;
};
- GrowableArray<TagAndArray> array;
+ Vector<TagAndArray> vec;
for (size_t i = 0; i < 100; i++) {
TagAndArray elem;
elem.tag = i;
for (size_t j = 0; j < i; j++) {
- ASSERT_TRUE(elem.array.Push(j));
+ ASSERT_TRUE(elem.vec.Push(j));
}
- ASSERT_TRUE(array.Push(std::move(elem)));
+ ASSERT_TRUE(vec.Push(std::move(elem)));
}
- EXPECT_EQ(array.size(), static_cast<size_t>(100));
+ EXPECT_EQ(vec.size(), static_cast<size_t>(100));
- GrowableArray<TagAndArray> array_moved(std::move(array));
- EXPECT_EQ(array_moved.size(), static_cast<size_t>(100));
+ Vector<TagAndArray> vec_moved(std::move(vec));
+ EXPECT_EQ(vec_moved.size(), static_cast<size_t>(100));
size_t count = 0;
- for (const TagAndArray &elem : array_moved) {
+ for (const TagAndArray &elem : vec_moved) {
// Test the square bracket operator returns the same value as iteration.
- EXPECT_EQ(&elem, &array_moved[count]);
+ EXPECT_EQ(&elem, &vec_moved[count]);
EXPECT_EQ(elem.tag, count);
- EXPECT_EQ(elem.array.size(), count);
+ EXPECT_EQ(elem.vec.size(), count);
for (size_t j = 0; j < count; j++) {
- EXPECT_EQ(elem.array[j], j);
+ EXPECT_EQ(elem.vec[j], j);
}
count++;
}