@@ -121,18 +121,13 @@ class BundleWriter {
121
121
_writeTypeAliasElements (libraryElement.typeAliases);
122
122
123
123
_sink.writeList (libraryElement.topLevelVariables, (element) {
124
- _writeReference2 (element.reference);
124
+ _writeReference (element.reference);
125
125
_sink.writeList (element.fragments, _writeFragmentId);
126
126
});
127
127
128
128
_writeGetterElements (libraryElement.getters);
129
129
_writeSetterElements (libraryElement.setters);
130
-
131
- _sink.writeList (libraryElement.topLevelVariables, (variableElement) {
132
- _writeReference2 (variableElement.reference);
133
- _writeOptionalReference (variableElement.getter2? .reference);
134
- _writeOptionalReference (variableElement.setter2? .reference);
135
- });
130
+ _writeVariableGetterSetterLinking (libraryElement.topLevelVariables);
136
131
137
132
// Write resolution data for the library.
138
133
_writeResolutionOffset ();
@@ -149,7 +144,7 @@ class BundleWriter {
149
144
150
145
void _writeClassElements (List <ClassElementImpl > elements) {
151
146
_sink.writeList (elements, (element) {
152
- _writeReference2 (element.reference);
147
+ _writeReference (element.reference);
153
148
_sink.writeList (element.fragments, (fragment) {
154
149
_writeFragmentId (fragment);
155
150
});
@@ -200,7 +195,7 @@ class BundleWriter {
200
195
201
196
void _writeConstructorElements (List <ConstructorElementImpl > elements) {
202
197
_sink.writeList (elements, (element) {
203
- _writeReference2 (element.reference);
198
+ _writeReference (element.reference);
204
199
_sink.writeList (element.fragments, _writeFragmentId);
205
200
});
206
201
}
@@ -264,7 +259,7 @@ class BundleWriter {
264
259
265
260
void _writeEnumElements (List <EnumElementImpl > elements) {
266
261
_sink.writeList (elements, (element) {
267
- _writeReference2 (element.reference);
262
+ _writeReference (element.reference);
268
263
_sink.writeList (element.fragments, (fragment) {
269
264
_writeFragmentId (fragment);
270
265
});
@@ -329,7 +324,7 @@ class BundleWriter {
329
324
330
325
void _writeExtensionElements (List <ExtensionElementImpl > elements) {
331
326
_sink.writeList (elements, (element) {
332
- _writeReference2 (element.reference);
327
+ _writeReference (element.reference);
333
328
_sink.writeList (element.fragments, (fragment) {
334
329
_writeFragmentId (fragment);
335
330
});
@@ -368,7 +363,7 @@ class BundleWriter {
368
363
369
364
void _writeExtensionTypeElements (List <ExtensionTypeElementImpl > elements) {
370
365
_sink.writeList (elements, (element) {
371
- _writeReference2 (element.reference);
366
+ _writeReference (element.reference);
372
367
_sink.writeList (element.fragments, (fragment) {
373
368
_writeFragmentId (fragment);
374
369
});
@@ -417,7 +412,7 @@ class BundleWriter {
417
412
418
413
void _writeFieldElements (List <FieldElementImpl > elements) {
419
414
_sink.writeList (elements, (element) {
420
- _writeReference2 (element.reference);
415
+ _writeReference (element.reference);
421
416
_sink.writeList (element.fragments, _writeFragmentId);
422
417
});
423
418
}
@@ -480,7 +475,7 @@ class BundleWriter {
480
475
481
476
void _writeGetterElements (List <GetterElementImpl > elements) {
482
477
_sink.writeList (elements, (element) {
483
- _writeReference2 (element.reference);
478
+ _writeReference (element.reference);
484
479
_sink.writeList (element.fragments, _writeFragmentId);
485
480
486
481
_writeElementResolution (() {
@@ -532,7 +527,7 @@ class BundleWriter {
532
527
void _writeLibraryImportPrefixFragment (PrefixFragmentImpl ? fragment) {
533
528
_sink.writeOptionalObject (fragment, (fragment) {
534
529
_writeFragmentName (fragment);
535
- _writeReference2 (fragment.element.reference);
530
+ _writeReference (fragment.element.reference);
536
531
_sink.writeBool (fragment.isDeferred);
537
532
});
538
533
}
@@ -546,12 +541,12 @@ class BundleWriter {
546
541
547
542
void _writeLoadLibraryFunctionReferences (LibraryElementImpl library) {
548
543
var element = library.loadLibraryFunction2;
549
- _writeReference2 (element.reference);
544
+ _writeReference (element.reference);
550
545
}
551
546
552
547
void _writeMethodElements (List <MethodElementImpl > elements) {
553
548
_sink.writeList (elements, (element) {
554
- _writeReference2 (element.reference);
549
+ _writeReference (element.reference);
555
550
_sink.writeList (element.fragments, _writeFragmentId);
556
551
557
552
_writeElementResolution (() {
@@ -579,7 +574,7 @@ class BundleWriter {
579
574
580
575
void _writeMixinElements (List <MixinElementImpl > elements) {
581
576
_sink.writeList (elements, (element) {
582
- _writeReference2 (element.reference);
577
+ _writeReference (element.reference);
583
578
_sink.writeList (element.fragments, (fragment) {
584
579
_writeFragmentId (fragment);
585
580
});
@@ -639,10 +634,7 @@ class BundleWriter {
639
634
}
640
635
641
636
void _writeOptionalReference (Reference ? reference) {
642
- _sink.writeOptionalObject (reference, (reference) {
643
- var index = _references._indexOfReference (reference);
644
- _sink.writeUInt30 (index);
645
- });
637
+ _sink.writeOptionalObject (reference, _writeReference);
646
638
}
647
639
648
640
// TODO(scheglov): Deduplicate parameter writing implementation.
@@ -687,7 +679,7 @@ class BundleWriter {
687
679
_writeDirectiveUri (element.uri);
688
680
}
689
681
690
- void _writeReference2 (Reference ? reference) {
682
+ void _writeReference (Reference reference) {
691
683
var index = _references._indexOfReference (reference);
692
684
_sink.writeUInt30 (index);
693
685
}
@@ -700,7 +692,7 @@ class BundleWriter {
700
692
701
693
void _writeSetterElements (List <SetterElementImpl > elements) {
702
694
_sink.writeList (elements, (element) {
703
- _writeReference2 (element.reference);
695
+ _writeReference (element.reference);
704
696
_sink.writeList (element.fragments, _writeFragmentId);
705
697
706
698
_writeElementResolution (() {
@@ -726,7 +718,7 @@ class BundleWriter {
726
718
List <TopLevelFunctionElementImpl > elements,
727
719
) {
728
720
_sink.writeList (elements, (element) {
729
- _writeReference2 (element.reference);
721
+ _writeReference (element.reference);
730
722
_sink.writeList (element.fragments, _writeFragmentId);
731
723
732
724
_writeElementResolution (() {
@@ -761,7 +753,7 @@ class BundleWriter {
761
753
762
754
void _writeTypeAliasElements (List <TypeAliasElementImpl > elements) {
763
755
_sink.writeList (elements, (element) {
764
- _writeReference2 (element.reference);
756
+ _writeReference (element.reference);
765
757
_sink.writeList (element.fragments, _writeFragmentId);
766
758
// TODO(scheglov): resolution too?
767
759
});
@@ -835,7 +827,7 @@ class BundleWriter {
835
827
List <PropertyInducingElementImpl > variables,
836
828
) {
837
829
_sink.writeList (variables, (variable) {
838
- _writeReference2 (variable.reference);
830
+ _writeReference (variable.reference);
839
831
_writeOptionalReference (variable.getter2? .reference);
840
832
_writeOptionalReference (variable.setter2? .reference);
841
833
});
@@ -1338,21 +1330,22 @@ class _BundleWriterReferences {
1338
1330
}
1339
1331
}
1340
1332
1341
- int _indexOfReference (Reference ? reference) {
1342
- if (reference == null ) return 0 ;
1343
- if (reference.parent == null ) return 0 ;
1344
-
1333
+ int _indexOfReference (Reference reference) {
1345
1334
var index = reference.index;
1346
1335
if (index != null ) return index;
1347
1336
1348
- var parentIndex = _indexOfReference (reference.parent);
1349
- _referenceParents.add (parentIndex);
1350
- _referenceNames.add (reference.name);
1337
+ if (reference.parent case var parent? ) {
1338
+ var parentIndex = _indexOfReference (parent);
1339
+ _referenceParents.add (parentIndex);
1340
+ _referenceNames.add (reference.name);
1351
1341
1352
- index = _references.length;
1353
- reference.index = index;
1354
- _references.add (reference);
1355
- return index;
1342
+ index = _references.length;
1343
+ reference.index = index;
1344
+ _references.add (reference);
1345
+ return index;
1346
+ } else {
1347
+ return 0 ;
1348
+ }
1356
1349
}
1357
1350
}
1358
1351
0 commit comments