mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-04 17:10:47 +00:00
Add rdcarray helper for "resize array up to this index if smaller"
* This is a common enough operation to warrant a helper, as an alternative to vec.resize(RDCMAX(index + 1, vec.size())
This commit is contained in:
@@ -251,6 +251,16 @@ public:
|
||||
allocatedCount = s;
|
||||
}
|
||||
|
||||
void resize_for_index(size_t s)
|
||||
{
|
||||
// do nothing if we're already big enough
|
||||
if(size() >= s + 1)
|
||||
return;
|
||||
|
||||
// otherwise resize so that [s] is valid
|
||||
resize(s + 1);
|
||||
}
|
||||
|
||||
void resize(size_t s)
|
||||
{
|
||||
// do nothing if we're already this size
|
||||
|
||||
@@ -463,6 +463,43 @@ TEST_CASE("Test array type", "[basictypes]")
|
||||
CHECK(vec[1] == 5);
|
||||
};
|
||||
|
||||
SECTION("resize_for_index")
|
||||
{
|
||||
rdcarray<int> test;
|
||||
|
||||
CHECK(test.empty());
|
||||
|
||||
test.resize_for_index(0);
|
||||
|
||||
CHECK(test.size() == 1);
|
||||
CHECK(test.capacity() >= 1);
|
||||
|
||||
test.resize_for_index(5);
|
||||
|
||||
CHECK(test.size() == 5);
|
||||
CHECK(test.capacity() >= 5);
|
||||
|
||||
test.resize_for_index(5);
|
||||
|
||||
CHECK(test.size() == 5);
|
||||
CHECK(test.capacity() >= 5);
|
||||
|
||||
test.resize_for_index(3);
|
||||
|
||||
CHECK(test.size() == 5);
|
||||
CHECK(test.capacity() >= 5);
|
||||
|
||||
test.resize_for_index(0);
|
||||
|
||||
CHECK(test.size() == 5);
|
||||
CHECK(test.capacity() >= 5);
|
||||
|
||||
test.resize_for_index(9);
|
||||
|
||||
CHECK(test.size() == 9);
|
||||
CHECK(test.capacity() >= 9);
|
||||
};
|
||||
|
||||
SECTION("Check construction")
|
||||
{
|
||||
rdcarray<ConstructorCounter> test;
|
||||
|
||||
Reference in New Issue
Block a user