mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-05 13:08:58 +00:00
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:
committed by
Wouter van Oortmerssen
parent
dc61512f20
commit
4e5152d886
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user