From 4dc52fde82eee7154252150c1ac52be6e013d8b2 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Mon, 8 Dec 2025 12:26:56 +0300 Subject: [PATCH] rsx/common: Implement list insert for simple_array --- rpcs3/Emu/RSX/Common/simple_array.hpp | 29 +++++++++++++++++++++-- rpcs3/tests/test_simple_array.cpp | 34 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/simple_array.hpp b/rpcs3/Emu/RSX/Common/simple_array.hpp index 00dd6e7d95..6852e670fb 100644 --- a/rpcs3/Emu/RSX/Common/simple_array.hpp +++ b/rpcs3/Emu/RSX/Common/simple_array.hpp @@ -337,7 +337,7 @@ namespace rsx AUDIT(_loc < _size); const auto remaining = (_size - _loc); - memmove(pos + 1, pos, remaining * sizeof(Ty)); + std::memmove(pos + 1, pos, remaining * sizeof(Ty)); *pos = val; _size++; @@ -365,7 +365,7 @@ namespace rsx AUDIT(_loc < _size); const u32 remaining = (_size - _loc); - memmove(pos + 1, pos, remaining * sizeof(Ty)); + std::memmove(pos + 1, pos, remaining * sizeof(Ty)); *pos = val; _size++; @@ -373,6 +373,31 @@ namespace rsx return pos; } + iterator insert(iterator where, span_like auto const& values) + { + ensure(where >= _data); + const auto _loc = offset(where); + const auto in_size = static_cast(values.size()); + const auto in_size_bytes = in_size * sizeof(Ty); + + reserve(_size + in_size); + + if (_loc >= _size) + { + where = _data + _size; + std::memcpy(where, values.data(), in_size_bytes); + _size += in_size; + return where; + } + + const u32 remaining_bytes = (_size - _loc) * sizeof(Ty); + where = _data + _loc; + std::memmove(where + in_size, where, remaining_bytes); + std::memmove(where, values.data(), in_size_bytes); + _size += in_size; + return where; + } + void operator += (const rsx::simple_array& that) { const auto old_size = _size; diff --git a/rpcs3/tests/test_simple_array.cpp b/rpcs3/tests/test_simple_array.cpp index 8d64599b96..ebedff861d 100644 --- a/rpcs3/tests/test_simple_array.cpp +++ b/rpcs3/tests/test_simple_array.cpp @@ -324,6 +324,40 @@ namespace rsx EXPECT_EQ(arr.find_if(FN(x == 99)), nullptr); } + TEST(SimpleArray, InsertArray) + { + rsx::simple_array arr{ + 0, 1, 2, 6, 7, 8, 9 + }; + + const std::vector tail{ + 10, 11, 12 + }; + + const std::vector mid{ + 3, 4, 5 + }; + + // Insert end + arr.insert(arr.end(), tail); + EXPECT_EQ(arr.size(), 10); + + // Insert mid + auto it = arr.begin(); + std::advance(it, 3); + it = arr.insert(it, mid); + + EXPECT_EQ(arr.size(), 13); + EXPECT_EQ(std::distance(arr.begin(), it), 3); + EXPECT_EQ(*it, 3); + + // Verify + for (unsigned i = 0; i < arr.size(); ++i) + { + EXPECT_EQ(arr[i], static_cast(i)); + } + } + TEST(AlignedAllocator, Alloc) { auto ptr = rsx::aligned_allocator::malloc<256>(16);