UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMMutableArrayInline.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_VERSE_VM || defined(__INTELLISENSE__)
6
9#include "VerseVM/VVMInt.h"
11
12namespace Verse
13{
14
15inline void VMutableArray::AddValue(FAllocationContext Context, VValue Value)
16{
17 if (!GetData())
18 {
19 uint32 Num = 0;
20 uint32 Capacity = 4;
21 VBuffer NewBuffer = VBuffer(Context, Num, Capacity, DetermineArrayType(Value));
23 }
24 else if (GetArrayType() != EArrayType::VValue && GetArrayType() != DetermineArrayType(Value))
25 {
26 uint32 Capacity = this->Capacity();
27 if (Num() == Capacity) // Check our capacity before re-allocating as VValues
28 {
29 Capacity = Capacity * 2;
30 }
32 }
33 else if (Num() == Capacity())
34 {
35 uint32 NewCapacity = Capacity() * 2;
36 VBuffer NewBuffer = VBuffer(Context, Num(), NewCapacity, GetArrayType());
37 if (Num())
38 {
39 FMemory::Memcpy(NewBuffer.GetData(), GetData(), ByteLength());
40 }
41 // We might be copying around a VValue buffer, so we gotta barrier before we expose this buffer to the GC.
43 }
44
45 uint32 Index = Num();
46 V_DIE_UNLESS(Index < Capacity());
48 // The above store needs to happen before the GC sees an updated NumValues.
50 ++Buffer.Get().GetHeader()->NumValues;
51 if (::Verse::IsNullTerminatedString(GetArrayType()))
52 {
54 }
55}
56
57template <typename T>
58inline void VMutableArray::Append(FAllocationContext Context, VArrayBase& Array)
59{
60 checkSlow(GetArrayType() != EArrayType::None && GetArrayType() != EArrayType::VValue && GetArrayType() == Array.GetArrayType());
61 if (Array.Num())
62 {
63 const uint32 NewNumValues = Num() + Array.Num();
64 uint32 Capacity = this->Capacity();
65 if (NewNumValues > Capacity)
66 {
67 Capacity = NewNumValues * 2;
68 VBuffer NewBuffer = VBuffer(Context, NewNumValues, Capacity, GetArrayType());
69 if (Num())
70 {
71 FMemory::Memcpy(NewBuffer.GetData(), GetData(), ByteLength());
72 }
73 // We need the store of the array type in the buffer to happen
74 // before the GC sees the new buffer.
76 }
77 FMemory::Memcpy(GetData<T>() + Num(), Array.GetData<T>(), Array.ByteLength());
78 // We don't need to barrier here because the GC doesn't mark primitive arrays.
79 Buffer.Get().GetHeader()->NumValues = NewNumValues;
80 if (::Verse::IsNullTerminatedString(GetArrayType()))
81 {
83 }
84 }
85}
86
87template <>
88inline void VMutableArray::Append<TWriteBarrier<VValue>>(FAllocationContext Context, VArrayBase& Array)
89{
90 checkSlow(GetArrayType() == EArrayType::VValue);
91 for (uint32 Index = 0, End = Array.Num(); Index < End; ++Index)
92 {
93 AddValue(Context, Array.GetValue(Index));
94 }
95}
96
97inline VMutableArray& VMutableArray::Concat(FAllocationContext Context, VArrayBase& Lhs, VArrayBase& Rhs)
98{
99 VMutableArray& NewArray = VMutableArray::New(Context, 0, Lhs.Num() + Rhs.Num(), DetermineCombinedType(Lhs.GetArrayType(), Rhs.GetArrayType()));
100 NewArray.Append(Context, Lhs);
101 NewArray.Append(Context, Rhs);
102 return NewArray;
103}
104
105} // namespace Verse
106#endif // WITH_VERSE_VM
#define checkSlow(expr)
Definition AssertionMacros.h:332
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
@ Num
Definition MetalRHIPrivate.h:234
auto GetData(const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Get())
Definition StringConv.h:802
uint32_t uint32
Definition binka_ue_file_header.h:6
IAnalyticsPropertyStore::EStatusCode SetValue(TGetter &&GetterFn, TSetter &&SetterFn, const T &ProposedValue, TCompare &&ConditionFn)
Definition AnalyticsPropertyStore.cpp:34
FORCEINLINE UE_STRING_CLASS RhsType && Rhs
Definition String.cpp.inl:718
Definition Archive.h:36
U16 Index
Definition radfft.cpp:71
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160