mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-12-16 04:09:07 +00:00
rsx/common: Implement list insert for simple_array
This commit is contained in:
parent
5688573b3d
commit
4dc52fde82
@ -337,7 +337,7 @@ namespace rsx
|
|||||||
AUDIT(_loc < _size);
|
AUDIT(_loc < _size);
|
||||||
|
|
||||||
const auto remaining = (_size - _loc);
|
const auto remaining = (_size - _loc);
|
||||||
memmove(pos + 1, pos, remaining * sizeof(Ty));
|
std::memmove(pos + 1, pos, remaining * sizeof(Ty));
|
||||||
|
|
||||||
*pos = val;
|
*pos = val;
|
||||||
_size++;
|
_size++;
|
||||||
@ -365,7 +365,7 @@ namespace rsx
|
|||||||
AUDIT(_loc < _size);
|
AUDIT(_loc < _size);
|
||||||
|
|
||||||
const u32 remaining = (_size - _loc);
|
const u32 remaining = (_size - _loc);
|
||||||
memmove(pos + 1, pos, remaining * sizeof(Ty));
|
std::memmove(pos + 1, pos, remaining * sizeof(Ty));
|
||||||
|
|
||||||
*pos = val;
|
*pos = val;
|
||||||
_size++;
|
_size++;
|
||||||
@ -373,6 +373,31 @@ namespace rsx
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iterator insert(iterator where, span_like<Ty> auto const& values)
|
||||||
|
{
|
||||||
|
ensure(where >= _data);
|
||||||
|
const auto _loc = offset(where);
|
||||||
|
const auto in_size = static_cast<u32>(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<Ty>& that)
|
void operator += (const rsx::simple_array<Ty>& that)
|
||||||
{
|
{
|
||||||
const auto old_size = _size;
|
const auto old_size = _size;
|
||||||
|
|||||||
@ -324,6 +324,40 @@ namespace rsx
|
|||||||
EXPECT_EQ(arr.find_if(FN(x == 99)), nullptr);
|
EXPECT_EQ(arr.find_if(FN(x == 99)), nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(SimpleArray, InsertArray)
|
||||||
|
{
|
||||||
|
rsx::simple_array<int> arr{
|
||||||
|
0, 1, 2, 6, 7, 8, 9
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::vector<int> tail{
|
||||||
|
10, 11, 12
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::vector<int> 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<int>(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(AlignedAllocator, Alloc)
|
TEST(AlignedAllocator, Alloc)
|
||||||
{
|
{
|
||||||
auto ptr = rsx::aligned_allocator::malloc<256>(16);
|
auto ptr = rsx::aligned_allocator::malloc<256>(16);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user