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

@@ -1119,6 +1119,18 @@ class GeneralGenerator : public BaseGenerator {
code += lang_.accessor_prefix + "__vector_as_arraysegment(";
code += NumToString(field.value.offset);
code += "); }\n";
// For direct blockcopying the data into a typed array
code += " public ";
code += GenTypeBasic(field.value.type.VectorType());
code += "[] Get";
code += MakeCamel(field.name, lang_.first_camel_upper);
code += "Array() { return ";
code += lang_.accessor_prefix + "__vector_as_array<";
code += GenTypeBasic(field.value.type.VectorType());
code += ">(";
code += NumToString(field.value.offset);
code += "); }\n";
break;
default: break;
}
@@ -1341,6 +1353,19 @@ class GeneralGenerator : public BaseGenerator {
code += ".Value";
code += "); return ";
code += "builder." + FunctionStart('E') + "ndVector(); }\n";
// For C#, include a block copy method signature.
if (lang_.language == IDLOptions::kCSharp) {
code += " public static " + GenVectorOffsetType() + " ";
code += FunctionStart('C') + "reate";
code += MakeCamel(field.name);
code += "VectorBlock(FlatBufferBuilder builder, ";
code += GenTypeBasic(vector_type) + "[] data) ";
code += "{ builder." + FunctionStart('S') + "tartVector(";
code += NumToString(elem_size);
code += ", data." + FunctionStart('L') + "ength, ";
code += NumToString(alignment);
code += "); builder.Add(data); return builder.EndVector(); }\n";
}
}
// Generate a method to start a vector, data to be added manually
// after.