mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-21 03:17:32 +00:00
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
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
6e185d06a7
commit
7b50004ec9
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user