diff options
author | Derek Bailey <derek.bailey@thermofisher.com> | 2018-07-26 13:44:40 -0700 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2018-07-26 13:44:40 -0700 |
commit | 7b50004ec9a1b86db2b1b61a9906e52227f62b35 (patch) | |
tree | 97ac7c68e8dadf76252c674e95509f8233ada9f6 /src | |
parent | 6e185d06a72272130047cb4fcddf5b751e76fca0 (diff) | |
download | flatbuffers-7b50004ec9a1b86db2b1b61a9906e52227f62b35.tar.gz flatbuffers-7b50004ec9a1b86db2b1b61a9906e52227f62b35.tar.bz2 flatbuffers-7b50004ec9a1b86db2b1b61a9906e52227f62b35.zip |
Performance Increase of Vector of Structures using .NET BlockCopy (#4830)
* Added Get<vector_name>Array() method for accessing vectors of structures in C# using Buffer.Blockcopy().
* Added Get<vector_name>Array() method for accessing vectors of structures in C# using Buffer.Blockcopy().
Added Create<Name>VectorBlock() method to add a typed array using Buffer.BlockCopy() to speed up creation of vector of arrays
New Lua files for namespace test
* fixed c++ style issue
Diffstat (limited to 'src')
-rw-r--r-- | src/idl_gen_general.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/idl_gen_general.cpp b/src/idl_gen_general.cpp index d3cc79b2..27eb8c40 100644 --- a/src/idl_gen_general.cpp +++ b/src/idl_gen_general.cpp @@ -1102,6 +1102,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; } @@ -1324,6 +1336,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. |