fix(containers): fix TArray lost all elements after move assignment

This commit is contained in:
Redstone1024 2024-11-02 23:07:05 +08:00
parent 728b91c317
commit 2bb0ddee5b
2 changed files with 5 additions and 3 deletions

View File

@ -29,7 +29,7 @@ void TestArrayTemplate()
TArray<int32, Allocator> ArrayB(4);
TArray<int32, Allocator> ArrayC(4, 4);
TArray<int32, Allocator> ArrayD(ArrayC);
TArray<int32, Allocator> ArrayE(MoveTemp(ArrayB));
TArray<int32, Allocator> ArrayE(MoveTemp(ArrayC));
TArray<int32, Allocator> ArrayF({ 0, 1, 2, 3 });
TArray<int32, Allocator> ArrayG;
@ -40,9 +40,9 @@ void TestArrayTemplate()
ArrayH = MoveTemp(ArrayE);
ArrayI = { 0, 1, 2, 3 };
always_check((ArrayC == TArray<int32, Allocator>({ 4, 4, 4, 4 })));
always_check((ArrayD == TArray<int32, Allocator>({ 4, 4, 4, 4 })));
always_check((ArrayG == TArray<int32, Allocator>({ 4, 4, 4, 4 })));
always_check((ArrayH == TArray<int32, Allocator>({ 4, 4, 4, 4 })));
always_check((ArrayF == TArray<int32, Allocator>({ 0, 1, 2, 3 })));
always_check((ArrayI == TArray<int32, Allocator>({ 0, 1, 2, 3 })));
}

View File

@ -189,7 +189,9 @@ public:
Memory::Destruct(Impl.Pointer, Num());
Impl->Deallocate(Impl.Pointer);
Impl.Pointer = InValue.Impl.Pointer;
Impl.ArrayNum = InValue.Num();
Impl.ArrayMax = InValue.Max();
Impl.Pointer = InValue.Impl.Pointer;
InValue.Impl.ArrayNum = 0;
InValue.Impl.ArrayMax = InValue.Impl->CalculateSlackReserve(InValue.Num());