MCPcopy Create free account
hub / github.com/apache/arrow / CheckReserve

Method CheckReserve

cpp/src/arrow/util/small_vector_test.cc:198–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196
197 template <size_t N>
198 void CheckReserve(size_t max_size, bool expect_overflow) {
199 IntVectorType<N> ints;
200 ints.emplace_back(123);
201
202 size_t orig_capacity = ints.capacity();
203
204 ints.reserve(max_size / 3);
205 ASSERT_EQ(ints.capacity(), std::max(max_size / 3, orig_capacity));
206 ASSERT_EQ(ints.size(), 1);
207 ASSERT_EQ(ints[0], 123);
208
209 ints.reserve(4 * max_size / 5);
210 ASSERT_EQ(ints.capacity(), std::max(4 * max_size / 5, orig_capacity));
211 ASSERT_EQ(ints.size(), 1);
212 ASSERT_EQ(ints[0], 123);
213 ASSERT_EQ(UsesStaticStorage(ints), !expect_overflow);
214
215 size_t old_capacity = ints.capacity();
216 ints.reserve(max_size / 5); // no-op
217 ASSERT_EQ(ints.capacity(), old_capacity);
218 ASSERT_EQ(ints.size(), 1);
219 ASSERT_EQ(ints[0], 123);
220
221 ints.reserve(1); // no-op
222 ASSERT_EQ(ints.capacity(), old_capacity);
223 ASSERT_EQ(ints.size(), 1);
224 ASSERT_EQ(ints[0], 123);
225 }
226
227 void TestReserve() {
228 CheckReserve<Traits::TestSizeFor(12)>(12, /*expect_overflow=*/Traits::CanOverflow());

Callers

nothing calls this directly

Calls 5

UsesStaticStorageFunction · 0.85
emplace_backMethod · 0.80
capacityMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected