Mono Fix for Unsafe Mode (#4887)

* Added preprocessor define for C++ if Template Aliases are supported by the compiler

* Revert "Revert "Performance Increase of Vector of Structures using .NET BlockCopy (#4830)""

This reverts commit 1f5eae5d6a.

* Put<T> method was inside #if UNSAFE_BYTEBUFFER which caused compilation failure when building in unsafe mode

* Revert "Added preprocessor define for C++ if Template Aliases are supported by the compiler"

This reverts commit a75af73521.
This commit is contained in:
Derek Bailey
2018-08-20 16:31:44 -07:00
committed by Wouter van Oortmerssen
parent 1f5eae5d6a
commit d8f49e18d7
10 changed files with 617 additions and 6 deletions

View File

@@ -179,6 +179,18 @@ namespace FlatBuffers
_bb.PutFloat(_space -= sizeof(float), x);
}
/// <summary>
/// Puts an array of type T into this builder at the
/// current offset
/// </summary>
/// <typeparam name="T">The type of the input data </typeparam>
/// <param name="x">The array to copy data from</param>
public void Put<T>(T[] x)
where T : struct
{
_space = _bb.Put(_space, x);
}
public void PutDouble(double x)
{
_bb.PutDouble(_space -= sizeof(double), x);
@@ -245,6 +257,37 @@ namespace FlatBuffers
/// <param name="x">The `float` to add to the buffer.</param>
public void AddFloat(float x) { Prep(sizeof(float), 0); PutFloat(x); }
/// <summary>
/// Add an array of type T to the buffer (aligns the data and grows if necessary).
/// </summary>
/// <typeparam name="T">The type of the input data</typeparam>
/// <param name="x">The array to copy data from</param>
public void Add<T>(T[] x)
where T : struct
{
if (x == null)
{
throw new ArgumentNullException("Cannot add a null array");
}
if( x.Length == 0)
{
// don't do anything if the array is empty
return;
}
if(!ByteBuffer.IsSupportedType<T>())
{
throw new ArgumentException("Cannot add this Type array to the builder");
}
int size = ByteBuffer.SizeOf<T>();
// Need to prep on size (for data alignment) and then we pass the
// rest of the length (minus 1) as additional bytes
Prep(size, size * (x.Length - 1));
Put(x);
}
/// <summary>
/// Add a `double` to the buffer (aligns the data and grows if necessary).
/// </summary>