From d3555c51afc19f57dc10bffd05c0aa088aa0620e Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 29 Sep 2026 11:28:48 +0100 Subject: [PATCH] Use move helper for rdcarray move append * This makes a big difference for move-appending basic types like bytes or ints --- renderdoc/api/replay/rdcarray.h | 4 +-- renderdoc/replay/basic_types_tests.cpp | 35 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/renderdoc/api/replay/rdcarray.h b/renderdoc/api/replay/rdcarray.h index 0422fc324..0038d7049 100644 --- a/renderdoc/api/replay/rdcarray.h +++ b/renderdoc/api/replay/rdcarray.h @@ -568,8 +568,8 @@ public: inline void append(rdcarray &&in) { reserve(size() + in.size()); - for(size_t i = 0; i < in.size(); i++) - push_back(std::move(in[i])); + ItemCopyHelper::moveRange(data() + size(), in.data(), in.size()); + setUsedCount(usedCount + in.size()); // don't have to clear here, since moved object can be left in any indeterminate but valid state // (an all the members are in that state, while the array is fully valid), but this gives fewer // surprises. diff --git a/renderdoc/replay/basic_types_tests.cpp b/renderdoc/replay/basic_types_tests.cpp index 203804da1..366970c36 100644 --- a/renderdoc/replay/basic_types_tests.cpp +++ b/renderdoc/replay/basic_types_tests.cpp @@ -415,6 +415,15 @@ static void TestBasic() CHECK(test.size() == 7); CHECK(x == 10); CHECK(test[2] == 6); + + rdcarray other = {1, 2, 3}; + + test.append(other); + + CHECK(test.size() == 10); + CHECK(test[7] == 1); + CHECK(test[8] == 2); + CHECK(test[9] == 3); } static int32_t constructor = 0; @@ -1307,6 +1316,32 @@ TEST_CASE("Test array type", "[basictypes]") CHECK(movedDestructor == 17); CHECK(copyAssignment == 0); CHECK(moveAssignment == 0); + + // move append + rdcarray other = {1, 2, 3}; + + CHECK(valueConstructor == 8); + CHECK(copyConstructor == 5); + CHECK(moveConstructor == 21); + CHECK(destructor == 21); + CHECK(movedDestructor == 17); + CHECK(copyAssignment == 0); + CHECK(moveAssignment == 0); + + test.append(std::move(other)); + + CHECK(valueConstructor == 8); + CHECK(copyConstructor == 5); + CHECK(moveConstructor == 24); + CHECK(destructor == 24); + CHECK(movedDestructor == 20); + CHECK(copyAssignment == 0); + CHECK(moveAssignment == 0); + + CHECK(test.size() == 13); + CHECK(test[10].value == 1); + CHECK(test[11].value == 2); + CHECK(test[12].value == 3); }; };