@@ -132,8 +132,9 @@ class Builder {
132132 final int initialSize;
133133
134134 /// The list of existing VTable(s).
135- final List <int > _vTables = List <int >.filled (16 , 0 , growable: true )
136- ..length = 0 ;
135+ final List <int > _vTables;
136+
137+ final bool deduplicateTables;
137138
138139 ByteData _buf;
139140
@@ -170,8 +171,10 @@ class Builder {
170171 this .initialSize: 1024 ,
171172 bool internStrings = false ,
172173 Allocator allocator = const DefaultAllocator (),
174+ this .deduplicateTables = true ,
173175 }) : _allocator = allocator,
174- _buf = allocator.allocate (initialSize) {
176+ _buf = allocator.allocate (initialSize),
177+ _vTables = List .empty (growable: deduplicateTables) {
175178 if (internStrings) {
176179 _strings = new Map <String , int >();
177180 }
@@ -333,17 +336,20 @@ class Builder {
333336 int ? vTableTail;
334337 {
335338 currentVTable.computeFieldOffsets (tableTail);
339+
336340 // Try to find an existing compatible VTable.
337- // Search backward - more likely to have recently used one
338- for (int i = _vTables.length - 1 ; i >= 0 ; i-- ) {
339- final int vt2Offset = _vTables[i];
340- final int vt2Start = _buf.lengthInBytes - vt2Offset;
341- final int vt2Size = _buf.getUint16 (vt2Start, Endian .little);
342-
343- if (currentVTable._vTableSize == vt2Size &&
344- currentVTable._offsetsMatch (vt2Start, _buf)) {
345- vTableTail = vt2Offset;
346- break ;
341+ if (deduplicateTables) {
342+ // Search backward - more likely to have recently used one
343+ for (int i = _vTables.length - 1 ; i >= 0 ; i-- ) {
344+ final int vt2Offset = _vTables[i];
345+ final int vt2Start = _buf.lengthInBytes - vt2Offset;
346+ final int vt2Size = _buf.getUint16 (vt2Start, Endian .little);
347+
348+ if (currentVTable._vTableSize == vt2Size &&
349+ currentVTable._offsetsMatch (vt2Start, _buf)) {
350+ vTableTail = vt2Offset;
351+ break ;
352+ }
347353 }
348354 }
349355 // Write a new VTable.
@@ -352,7 +358,7 @@ class Builder {
352358 vTableTail = _tail;
353359 currentVTable.tail = vTableTail;
354360 currentVTable.output (_buf, _buf.lengthInBytes - _tail);
355- _vTables.add (currentVTable.tail);
361+ if (deduplicateTables) _vTables.add (currentVTable.tail);
356362 }
357363 }
358364 // Set the VTable offset.
@@ -484,7 +490,7 @@ class Builder {
484490 _maxAlign = 1 ;
485491 _tail = 0 ;
486492 _currentVTable = null ;
487- _vTables.length = 0 ;
493+ if (deduplicateTables) _vTables. clear () ;
488494 if (_strings != null ) {
489495 _strings = new Map <String , int >();
490496 }
@@ -1298,6 +1304,7 @@ class _VTable {
12981304 fieldOffsets[field] = offset + 1 ;
12991305 }
13001306
1307+ @pragma ('vm:prefer-inline' )
13011308 bool _offsetsMatch (int vt2Start, ByteData buf) {
13021309 assert (offsetsComputed);
13031310 for (int i = 0 ; i < fieldOffsets.length; i++ ) {
@@ -1310,6 +1317,7 @@ class _VTable {
13101317 }
13111318
13121319 /// Fill the [fieldOffsets] field.
1320+ @pragma ('vm:prefer-inline' )
13131321 void computeFieldOffsets (int tableTail) {
13141322 assert (! offsetsComputed);
13151323 offsetsComputed = true ;
@@ -1321,6 +1329,7 @@ class _VTable {
13211329
13221330 /// Outputs this VTable to [buf] , which is is expected to be aligned to 16-bit
13231331 /// and have at least [numOfUint16] 16-bit words available.
1332+ @pragma ('vm:prefer-inline' )
13241333 void output (ByteData buf, int bufOffset) {
13251334 assert (offsetsComputed);
13261335 // VTable size.
0 commit comments