PropertyRefCacheBuilder
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace System.Text.Json.Serialization.Metadata
{
internal sealed class PropertyRefCacheBuilder
{
private readonly List<PropertyRef> _propertyRefs = new List<PropertyRef>();
private readonly HashSet<PropertyRef> _added = new HashSet<PropertyRef>();
public readonly PropertyRef[] OriginalCache = originalCache;
public int TotalCount => OriginalCache.Length + _propertyRefs.Count;
public PropertyRefCacheBuilder(PropertyRef[] originalCache)
{
}
public PropertyRef[] ToArray()
{
PropertyRef[] originalCache = OriginalCache;
List<PropertyRef> propertyRefs = _propertyRefs;
int num = 0;
PropertyRef[] array = new PropertyRef[originalCache.Length + propertyRefs.Count];
ReadOnlySpan<PropertyRef> readOnlySpan = new ReadOnlySpan<PropertyRef>(originalCache);
Span<PropertyRef> span = new Span<PropertyRef>(array);
readOnlySpan.CopyTo(span.Slice(num, readOnlySpan.Length));
num += readOnlySpan.Length;
Span<PropertyRef> span2 = CollectionsMarshal.AsSpan(propertyRefs);
span = new Span<PropertyRef>(array);
span2.CopyTo(span.Slice(num, span2.Length));
num += span2.Length;
return array;
}
public void TryAdd(PropertyRef propertyRef)
{
if (_added.Add(propertyRef))
_propertyRefs.Add(propertyRef);
}
}
}