summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDerek Bailey <derek.bailey@thermofisher.com>2018-07-26 13:44:40 -0700
committerWouter van Oortmerssen <aardappel@gmail.com>2018-07-26 13:44:40 -0700
commit7b50004ec9a1b86db2b1b61a9906e52227f62b35 (patch)
tree97ac7c68e8dadf76252c674e95509f8233ada9f6 /src
parent6e185d06a72272130047cb4fcddf5b751e76fca0 (diff)
downloadflatbuffers-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.cpp25
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.