Class ValueCollectionsMarshal
- Namespace
- Badeend.ValueCollections
- Assembly
- Badeend.ValueCollections.dll
Unsafe utility methods.
public static class ValueCollectionsMarshal
- Inheritance
-
ValueCollectionsMarshal
- Inherited Members
Methods
AsReadOnlySpan<T>(Builder)
Get a ReadOnlySpan<T> view over the current data in the
builder
.
Warning
The builder should not be built or mutated while the span is in use. Especially do not feed the span back into the builder itself using e.g. AddRange(params ReadOnlySpan<T>) or InsertRange(int, params ReadOnlySpan<T>).
public static ReadOnlySpan<T> AsReadOnlySpan<T>(ValueList<T>.Builder builder)
Parameters
Returns
- ReadOnlySpan<T>
Type Parameters
T
AsSpan<T>(Builder)
Get a Span<T> view over the current data in the
builder
.
Warning
The builder should not be built or mutated while the span is in use. Especially do not feed the span back into the builder itself using e.g. AddRange(params ReadOnlySpan<T>) or InsertRange(int, params ReadOnlySpan<T>).
public static Span<T> AsSpan<T>(ValueList<T>.Builder builder)
Parameters
Returns
- Span<T>
Type Parameters
T
Exceptions
- InvalidOperationException
The collection has already been built. If you don't need mutable access to the data, use the AsReadOnlySpan<T>(Builder) method instead which continues to work even after the collection has been built.
AsValueList<T>(T[])
Create a new ValueList<T> using the provided mutable array as its backing store. This operation only allocates a fixed amount of memory for the new ValueList instance. For the actual content it reuses the provided array instead of copying it over.
Warning
Ownership of the array is moved into the ValueList. It is the caller's responsibility to never mutate the array ever again.
public static ValueList<T> AsValueList<T>(T[] items)
Parameters
items
T[]
Returns
- ValueList<T>
Type Parameters
T
AsValueSlice<T>(T[])
Create a new ValueSlice<T> using the provided mutable array as its backing store. This operation does not allocate any memory.
Warning
Ownership of the array is moved into the ValueSlice. It is the caller's responsibility to never mutate the array ever again.
public static ValueSlice<T> AsValueSlice<T>(T[] items)
Parameters
items
T[]
Returns
- ValueSlice<T>
Type Parameters
T
GetValueRefOrNullRef<TKey, TValue>(ValueDictionary<TKey, TValue>, TKey)
Get a reference to a value in the dictionary, or a null ref if it does not exist.
public static ref readonly TValue GetValueRefOrNullRef<TKey, TValue>(ValueDictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull
Parameters
dictionary
ValueDictionary<TKey, TValue>key
TKey
Returns
- TValue
Type Parameters
TKey
TValue
Remarks
Note that a "null ref" is not the same as a reference to a
null
value. A null ref can be detected by calling Unsafe.IsNullRef
.
GetValueRefOrNullRef<TKey, TValue>(Builder, TKey)
Get a mutable reference to a value in the dictionary, or a null ref if it does not exist.
Warning
The builder should not be built or mutated while the returned reference is still in use.
public static ref TValue GetValueRefOrNullRef<TKey, TValue>(ValueDictionary<TKey, TValue>.Builder builder, TKey key) where TKey : notnull
Parameters
builder
ValueDictionary<TKey, TValue>.Builderkey
TKey
Returns
- TValue
Type Parameters
TKey
TValue
Remarks
Note that a "null ref" is not the same as a reference to a
null
value. A null ref can be detected by calling Unsafe.IsNullRef
.
SetCount<T>(Builder, int)
Update the count of the builder
.
Warning
When increasing the count, this may expose uninitialized, garbage data.
public static void SetCount<T>(ValueList<T>.Builder builder, int count)
Parameters
Type Parameters
T