Java: Calculation of vtable and vtable size moved to the __init method. (#5210)

vtable and vtable size depends only on `Table#bb_pos` but calculated in
`Table#_offset` method on each field lookup.
Doing this with every call of `Table#__offset` is redundant.

These values can be read once with change of `Table#bb_pos` and reused
for any field lookup.
This commit is contained in:
Kulikov Alexey
2019-02-26 05:45:29 +07:00
committed by Wouter van Oortmerssen
parent dc61512f20
commit 4e5152d886
20 changed files with 39 additions and 19 deletions

View File

@@ -874,7 +874,15 @@ class GeneralGenerator : public BaseGenerator {
// accessor object. This is to allow object reuse.
code += " public void __init(int _i, ByteBuffer _bb) ";
code += "{ " + lang_.accessor_prefix + "bb_pos = _i; ";
code += lang_.accessor_prefix + "bb = _bb; }\n";
code += lang_.accessor_prefix + "bb = _bb; ";
if (!struct_def.fixed && lang_.language == IDLOptions::kJava) {
code += lang_.accessor_prefix + "vtable_start = " + lang_.accessor_prefix + "bb_pos - ";
code += lang_.accessor_prefix + "bb." + FunctionStart('G') + "etInt(";
code += lang_.accessor_prefix + "bb_pos); " + lang_.accessor_prefix + "vtable_size = ";
code += lang_.accessor_prefix + "bb." + FunctionStart('G') + "etShort(";
code += lang_.accessor_prefix + "vtable_start); ";
}
code += "}\n";
code +=
" public " + struct_def.name + " __assign(int _i, ByteBuffer _bb) ";
code += "{ __init(_i, _bb); return this; }\n\n";