Skip to content

Commit 3de1728

Browse files
authored
Improve performance of documenting by 10%. (#2260)
* Improve performance of documenting by 10%. This is mostly accomplished by _not_ analyzing libraries for hints. In addition, a few other tweaks are made, code quality.
1 parent d23db1b commit 3de1728

File tree

3 files changed

+19
-29
lines changed

3 files changed

+19
-29
lines changed

lib/src/model/model_element.dart

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -752,22 +752,14 @@ abstract class ModelElement extends Canonicalization
752752
@override
753753
bool get isCanonical {
754754
if (!isPublic) return false;
755-
if (library == canonicalLibrary) {
756-
if (this is Inheritable) {
757-
var i = (this as Inheritable);
758-
// If we're the defining element, or if the defining element is not
759-
// in the set of libraries being documented, then this element
760-
// should be treated as canonical (given library == canonicalLibrary).
761-
if (i.enclosingElement == i.canonicalEnclosingContainer) {
762-
return true;
763-
} else {
764-
return false;
765-
}
766-
}
767-
// If there's no inheritance to deal with, we're done.
768-
return true;
769-
}
770-
return false;
755+
if (library != canonicalLibrary) return false;
756+
// If there's no inheritance to deal with, we're done.
757+
if (this is! Inheritable) return true;
758+
var i = this as Inheritable;
759+
// If we're the defining element, or if the defining element is not in the
760+
// set of libraries being documented, then this element should be treated as
761+
// canonical (given library == canonicalLibrary).
762+
return i.enclosingElement == i.canonicalEnclosingContainer;
771763
}
772764

773765
String _htmlDocumentation;

lib/src/model/package_builder.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,10 @@ class PubPackageBuilder implements PackageBuilder {
163163
if (_driver == null) {
164164
var log = PerformanceLog(null);
165165
var scheduler = AnalysisDriverScheduler(log);
166-
var options = AnalysisOptionsImpl();
167-
168-
// TODO(jcollins-g): pass in an ExperimentStatus instead?
169-
options.contextFeatures =
170-
FeatureSet.fromEnableFlags(config.enableExperiment);
166+
var options = AnalysisOptionsImpl()
167+
..hint = false
168+
// TODO(jcollins-g): pass in an ExperimentStatus instead?
169+
..contextFeatures = FeatureSet.fromEnableFlags(config.enableExperiment);
171170

172171
// TODO(jcollins-g): Make use of currently not existing API for managing
173172
// many AnalysisDrivers

lib/src/model/package_graph.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,18 @@ class PackageGraph {
256256
bool allLibrariesAdded = false;
257257
bool _localDocumentationBuilt = false;
258258

259+
Set<String> _allRootDirs;
260+
259261
/// Returns true if there's at least one library documented in the package
260262
/// that has the same package path as the library for the given element.
263+
///
261264
/// Usable as a cross-check for dartdoc's canonicalization to generate
262265
/// warnings for ModelElement.isPublicAndPackageDocumented.
263-
Set<String> _allRootDirs;
264-
265266
bool packageDocumentedFor(ModelElement element) {
266267
_allRootDirs ??= {
267268
...(publicLibraries.map((l) => l.packageMeta?.resolvedDir))
268269
};
269-
return (_allRootDirs.contains(element.library.packageMeta?.resolvedDir));
270+
return _allRootDirs.contains(element.library.packageMeta?.resolvedDir);
270271
}
271272

272273
PackageWarningCounter get packageWarningCounter => _packageWarningCounter;
@@ -584,7 +585,7 @@ class PackageGraph {
584585
}
585586
}
586587

587-
List<Library> get libraries =>
588+
Iterable<Library> get libraries =>
588589
packages.expand((p) => p.libraries).toList()..sort();
589590

590591
List<Library> _publicLibraries;
@@ -682,8 +683,7 @@ class PackageGraph {
682683
if (library.modelElementsMap.containsKey(searchElement)) {
683684
for (var modelElement in library.modelElementsMap[searchElement]) {
684685
if (modelElement.isCanonical) {
685-
_canonicalLibraryFor[e] = library;
686-
break;
686+
return _canonicalLibraryFor[e] = library;
687687
}
688688
}
689689
}
@@ -745,8 +745,7 @@ class PackageGraph {
745745
Class canonicalClass = findCanonicalModelElementFor(e.enclosingElement);
746746
if (canonicalClass != null) {
747747
candidates.addAll(canonicalClass.allCanonicalModelElements.where((m) {
748-
if (m.element == e) return true;
749-
return false;
748+
return m.element == e;
750749
}));
751750
}
752751
var matches = <ModelElement>{...candidates.where((me) => me.isCanonical)};

0 commit comments

Comments
 (0)