From bb1c0a5eee4a31c1ded5b37c1e3a41fd7068b06c Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sun, 15 Jun 2025 22:04:57 +0300 Subject: [PATCH] rsx/util: Support basic array merge --- rpcs3/Emu/RSX/Common/simple_array.hpp | 7 +++++++ rpcs3/tests/test_simple_array.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/rpcs3/Emu/RSX/Common/simple_array.hpp b/rpcs3/Emu/RSX/Common/simple_array.hpp index 06e0b1870d..033994547d 100644 --- a/rpcs3/Emu/RSX/Common/simple_array.hpp +++ b/rpcs3/Emu/RSX/Common/simple_array.hpp @@ -285,6 +285,13 @@ namespace rsx return pos; } + void operator += (const rsx::simple_array& that) + { + const auto old_size = _size; + resize(_size + that._size); + std::memcpy(data() + old_size, that.data(), that.size_bytes()); + } + void clear() { _size = 0; diff --git a/rpcs3/tests/test_simple_array.cpp b/rpcs3/tests/test_simple_array.cpp index f64e01200e..916284a6cd 100644 --- a/rpcs3/tests/test_simple_array.cpp +++ b/rpcs3/tests/test_simple_array.cpp @@ -189,4 +189,29 @@ namespace rsx EXPECT_EQ(arr[i], i + 1); } } + + TEST(SimpleArray, Merge) + { + rsx::simple_array arr{ 1 }; + rsx::simple_array arr2{ 2, 3, 4, 5, 6, 7, 8, 9 }; + rsx::simple_array arr3{ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 }; + + // Check small vector optimization + EXPECT_TRUE(arr.is_local_storage()); + + // Small vector optimization holds after append + arr += arr2; + EXPECT_TRUE(arr.is_local_storage()); + + // Exceed the boundary and we move into dynamic alloc + arr += arr3; + EXPECT_FALSE(arr.is_local_storage()); + + // Verify contents + EXPECT_EQ(arr.size(), 30); + for (int i = 0; i < 30; ++i) + { + EXPECT_EQ(arr[i], i + 1); + } + } }