@@ -132,8 +132,9 @@ class Builder {
132
132
final int initialSize;
133
133
134
134
/// 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;
137
138
138
139
ByteData _buf;
139
140
@@ -170,8 +171,10 @@ class Builder {
170
171
this .initialSize: 1024 ,
171
172
bool internStrings = false ,
172
173
Allocator allocator = const DefaultAllocator (),
174
+ this .deduplicateTables = true ,
173
175
}) : _allocator = allocator,
174
- _buf = allocator.allocate (initialSize) {
176
+ _buf = allocator.allocate (initialSize),
177
+ _vTables = List .empty (growable: deduplicateTables) {
175
178
if (internStrings) {
176
179
_strings = new Map <String , int >();
177
180
}
@@ -333,17 +336,20 @@ class Builder {
333
336
int ? vTableTail;
334
337
{
335
338
currentVTable.computeFieldOffsets (tableTail);
339
+
336
340
// 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
+ }
347
353
}
348
354
}
349
355
// Write a new VTable.
@@ -352,7 +358,7 @@ class Builder {
352
358
vTableTail = _tail;
353
359
currentVTable.tail = vTableTail;
354
360
currentVTable.output (_buf, _buf.lengthInBytes - _tail);
355
- _vTables.add (currentVTable.tail);
361
+ if (deduplicateTables) _vTables.add (currentVTable.tail);
356
362
}
357
363
}
358
364
// Set the VTable offset.
@@ -484,7 +490,7 @@ class Builder {
484
490
_maxAlign = 1 ;
485
491
_tail = 0 ;
486
492
_currentVTable = null ;
487
- _vTables.length = 0 ;
493
+ if (deduplicateTables) _vTables. clear () ;
488
494
if (_strings != null ) {
489
495
_strings = new Map <String , int >();
490
496
}
@@ -1298,6 +1304,7 @@ class _VTable {
1298
1304
fieldOffsets[field] = offset + 1 ;
1299
1305
}
1300
1306
1307
+ @pragma ('vm:prefer-inline' )
1301
1308
bool _offsetsMatch (int vt2Start, ByteData buf) {
1302
1309
assert (offsetsComputed);
1303
1310
for (int i = 0 ; i < fieldOffsets.length; i++ ) {
@@ -1310,6 +1317,7 @@ class _VTable {
1310
1317
}
1311
1318
1312
1319
/// Fill the [fieldOffsets] field.
1320
+ @pragma ('vm:prefer-inline' )
1313
1321
void computeFieldOffsets (int tableTail) {
1314
1322
assert (! offsetsComputed);
1315
1323
offsetsComputed = true ;
@@ -1321,6 +1329,7 @@ class _VTable {
1321
1329
1322
1330
/// Outputs this VTable to [buf] , which is is expected to be aligned to 16-bit
1323
1331
/// and have at least [numOfUint16] 16-bit words available.
1332
+ @pragma ('vm:prefer-inline' )
1324
1333
void output (ByteData buf, int bufOffset) {
1325
1334
assert (offsetsComputed);
1326
1335
// VTable size.
0 commit comments