@@ -4557,17 +4557,15 @@ class Category extends LibraryContainer implements Comparable<Category> {
4557
4557
class Package extends LibraryContainer implements Comparable <Package >, Privacy {
4558
4558
String _name;
4559
4559
PackageGraph _packageGraph;
4560
+
4561
+ final Map <String , Category > _categoryToContainer = {};
4560
4562
Package (this ._name, this ._packageGraph);
4561
4563
4562
4564
/// Return true if the code has defined non-default categories for libraries
4563
4565
/// in this package.
4564
4566
bool get hasCategories => categories.isNotEmpty;
4565
4567
4566
- LibraryContainer _defaultCategory;
4567
- LibraryContainer get defaultCategory {
4568
- if (_defaultCategory == null ) _buildCategories ();
4569
- return _defaultCategory;
4570
- }
4568
+ LibraryContainer get defaultCategory => categoryToContainer[null ];
4571
4569
4572
4570
bool _isPublic;
4573
4571
@override
@@ -4587,26 +4585,28 @@ class Package extends LibraryContainer implements Comparable<Package>, Privacy {
4587
4585
@override
4588
4586
List <Library > get publicLibraries => super .publicLibraries;
4589
4587
4590
- void _buildCategories () {
4591
- Map <String , Category > categoryToContainer = {
4592
- null : new Category (null , this , dartdocOptions)
4593
- };
4594
- for (Library lib in libraries) {
4595
- String category = lib.category;
4596
- categoryToContainer.putIfAbsent (
4597
- category, () => new Category (category, this , dartdocOptions));
4598
- categoryToContainer[category]._libraries.add (lib);
4588
+ // A map of category name to the category itself.
4589
+ Map <String , Category > get categoryToContainer {
4590
+ if (_categoryToContainer.isEmpty) {
4591
+ _categoryToContainer[null ] = new Category (null , this , dartdocOptions);
4592
+ for (Library lib in libraries) {
4593
+ String category = lib.category;
4594
+ _categoryToContainer.putIfAbsent (
4595
+ category, () => new Category (category, this , dartdocOptions));
4596
+ _categoryToContainer[category]._libraries.add (lib);
4597
+ }
4599
4598
}
4600
- _categories = categoryToContainer.values
4601
- .where ((c) => c.name != null )
4602
- .toList ()
4603
- ..sort ();
4604
- _defaultCategory = categoryToContainer[null ];
4599
+ return _categoryToContainer;
4605
4600
}
4606
4601
4607
4602
List <LibraryContainer > _categories;
4608
4603
List <LibraryContainer > get categories {
4609
- if (_categories == null ) _buildCategories ();
4604
+ if (_categories == null ) {
4605
+ _categories = categoryToContainer.values
4606
+ .where ((c) => c.name != null )
4607
+ .toList ()
4608
+ ..sort ();
4609
+ }
4610
4610
return _categories;
4611
4611
}
4612
4612
0 commit comments