Skip to content

Commit 962d68f

Browse files
authored
Convert many fields on Container and TopLevelContainer to getters (#3710)
These were late, final, and public, my least favorite thing. The idea, historically, behind late final fields in dartdoc is caching. If a value is expensive to calculate, like a big list of things, and we have to access that value a few times, best to calculate it once. But some late final fields are only accessed while rendering HTML, accessed from the rendered templates. And typically only accessed once. The '*Sorted' fields definitely fall into this bucket. So I made them all getters, and then benchmarked with the googleapis package, and found no significant change in time-to-document, or max RSS.
1 parent 353b426 commit 962d68f

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

lib/src/generator/templates.runtime_renderers.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -14420,7 +14420,7 @@ class _Renderer_TopLevelContainer extends RendererBase<TopLevelContainer> {
1442014420
renderVariable: (CT_ c, Property<CT_> self,
1442114421
List<String> remainingNames) =>
1442214422
self.renderSimpleVariable(
14423-
c, remainingNames, 'Iterable<TopLevelVariable>'),
14423+
c, remainingNames, 'List<TopLevelVariable>'),
1442414424
renderIterable: (CT_ c, RendererBase<CT_> r,
1442514425
List<MustachioNode> ast, StringSink sink) {
1442614426
return c.publicConstantsSorted.map((e) =>

lib/src/model/container.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ abstract class Container extends ModelElement
9797
@nonVirtual
9898
bool get hasPublicInstanceMethods => instanceMethods.any((e) => e.isPublic);
9999

100-
late final List<Method> publicInstanceMethodsSorted =
100+
List<Method> get publicInstanceMethodsSorted =>
101101
instanceMethods.wherePublic.toList(growable: false)..sort();
102102

103103
@nonVirtual
@@ -113,7 +113,7 @@ abstract class Container extends ModelElement
113113
bool get hasPublicInstanceOperators =>
114114
instanceOperators.any((e) => e.isPublic);
115115

116-
late final List<Operator> publicInstanceOperatorsSorted =
116+
List<Operator> get publicInstanceOperatorsSorted =>
117117
instanceOperators.wherePublic.toList(growable: false)..sort();
118118

119119
/// Fields fully declared in this [Container].
@@ -128,14 +128,14 @@ abstract class Container extends ModelElement
128128
@nonVirtual
129129
bool get hasPublicInstanceFields => instanceFields.any((e) => e.isPublic);
130130

131-
late final List<Field> publicInstanceFieldsSorted =
131+
List<Field> get publicInstanceFieldsSorted =>
132132
instanceFields.wherePublic.toList(growable: false)..sort(byName);
133133

134134
Iterable<Field> get constantFields => declaredFields.where((f) => f.isConst);
135135

136136
bool get hasPublicConstantFields => constantFields.any((e) => e.isPublic);
137137

138-
late final List<Field> publicConstantFieldsSorted =
138+
List<Field> get publicConstantFieldsSorted =>
139139
constantFields.wherePublic.toList(growable: false)..sort(byName);
140140

141141
/// The total list of public enum values.
@@ -194,7 +194,7 @@ abstract class Container extends ModelElement
194194

195195
bool get hasPublicStaticFields => staticFields.any((e) => e.isPublic);
196196

197-
late final List<Field> publicStaticFieldsSorted =
197+
List<Field> get publicStaticFieldsSorted =>
198198
staticFields.wherePublic.toList(growable: false)..sort();
199199

200200
Iterable<Field> get staticFields => declaredFields.where((f) => f.isStatic);
@@ -205,15 +205,15 @@ abstract class Container extends ModelElement
205205
bool get hasPublicVariableStaticFields =>
206206
variableStaticFields.any((e) => e.isPublic);
207207

208-
late final List<Field> publicVariableStaticFieldsSorted =
208+
List<Field> get publicVariableStaticFieldsSorted =>
209209
variableStaticFields.wherePublic.toList(growable: false)..sort();
210210

211211
Iterable<Method> get staticMethods =>
212212
declaredMethods.where((m) => m.isStatic);
213213

214214
bool get hasPublicStaticMethods => staticMethods.any((e) => e.isPublic);
215215

216-
late final List<Method> publicStaticMethodsSorted =
216+
List<Method> get publicStaticMethodsSorted =>
217217
staticMethods.wherePublic.toList(growable: false)..sort();
218218

219219
/// For subclasses to add items after the main pass but before the

lib/src/model/top_level_container.dart

+10-10
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,33 @@ mixin TopLevelContainer implements Nameable {
5555
// TODO(jcollins-g): Setting this type parameter to `Container` magically
5656
// fixes a number of type problems in the AOT compiler, but I am mystified as
5757
// to why that should be the case.
58-
late final List<Container> publicClassesSorted =
58+
List<Container> get publicClassesSorted =>
5959
classes.wherePublic.toList(growable: false)..sort();
6060

61-
late final List<Extension> publicExtensionsSorted =
61+
List<Extension> get publicExtensionsSorted =>
6262
extensions.wherePublic.toList(growable: false)..sort();
6363

64-
late final List<ExtensionType> publicExtensionTypesSorted =
64+
List<ExtensionType> get publicExtensionTypesSorted =>
6565
extensionTypes.wherePublic.toList(growable: false)..sort();
6666

67-
Iterable<TopLevelVariable> get publicConstantsSorted =>
67+
List<TopLevelVariable> get publicConstantsSorted =>
6868
constants.wherePublic.toList(growable: false)..sort();
6969

70-
late final List<Enum> publicEnumsSorted =
70+
List<Enum> get publicEnumsSorted =>
7171
enums.wherePublic.toList(growable: false)..sort();
7272

73-
late final List<Class> publicExceptionsSorted =
73+
List<Class> get publicExceptionsSorted =>
7474
exceptions.wherePublic.toList(growable: false)..sort();
7575

76-
late final List<ModelFunctionTyped> publicFunctionsSorted =
76+
List<ModelFunctionTyped> get publicFunctionsSorted =>
7777
functions.wherePublic.toList(growable: false)..sort();
7878

79-
late final List<Mixin> publicMixinsSorted =
79+
List<Mixin> get publicMixinsSorted =>
8080
mixins.wherePublic.toList(growable: false)..sort();
8181

82-
late final List<TopLevelVariable> publicPropertiesSorted =
82+
List<TopLevelVariable> get publicPropertiesSorted =>
8383
properties.wherePublic.toList(growable: false)..sort();
8484

85-
late final List<Typedef> publicTypedefsSorted =
85+
List<Typedef> get publicTypedefsSorted =>
8686
typedefs.wherePublic.toList(growable: false)..sort();
8787
}

0 commit comments

Comments
 (0)