Skip to content

Commit 75a4b52

Browse files
authored
Cache both exclude values and known parts (#2347)
1 parent ac1a1b0 commit 75a4b52

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

lib/src/dartdoc_options.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,13 @@ class DartdocOptionContext extends DartdocOptionContextBase
14351435
String get examplePathPrefix =>
14361436
optionSet['examplePathPrefix'].valueAt(context);
14371437

1438-
List<String> get exclude => optionSet['exclude'].valueAt(context);
1438+
/// A memoized calculation of exclusions.
1439+
// TODO(srawlins): This memoization saved a lot of time in unit testing, but
1440+
// is the first value in this class to be memoized. Memoize others?
1441+
/*late final*/ List<String> _exclude;
1442+
1443+
List<String> get exclude =>
1444+
_exclude ??= optionSet['exclude'].valueAt(context);
14391445

14401446
List<String> get excludePackages =>
14411447
optionSet['excludePackages'].valueAt(context);

lib/src/model/package_builder.dart

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class PubPackageBuilder implements PackageBuilder {
193193
/// If [filePath] is not a library, returns null.
194194
Future<DartDocResolvedLibrary> processLibrary(String filePath) async {
195195
var name = filePath;
196-
var directoryCurrentPath = config.resourceProvider.pathContext.current;
196+
var directoryCurrentPath = resourceProvider.pathContext.current;
197197

198198
if (name.startsWith(directoryCurrentPath)) {
199199
name = name.substring(directoryCurrentPath.length);
@@ -235,20 +235,15 @@ class PubPackageBuilder implements PackageBuilder {
235235
return null;
236236
}
237237

238-
Set<PackageMeta> _packageMetasForFiles(Iterable<String> files) {
239-
var metas = <PackageMeta>{};
240-
for (var filename in files) {
241-
metas.add(packageMetaProvider.fromFilename(filename));
242-
}
243-
return metas;
244-
}
238+
Set<PackageMeta> _packageMetasForFiles(Iterable<String> files) => {
239+
for (var filename in files) packageMetaProvider.fromFilename(filename),
240+
};
245241

246-
/// Parse libraries with the analyzer and invoke a callback with the
242+
/// Parses libraries with the analyzer and invokes [libraryAdder] with each
247243
/// result.
248244
///
249-
/// Uses the [libraries] parameter to prevent calling
250-
/// the callback more than once with the same [LibraryElement].
251-
/// Adds [LibraryElement]s found to that parameter.
245+
/// Uses [libraries] to prevent calling the callback more than once with the
246+
/// same [LibraryElement]. Adds each [LibraryElement] found to [libraries].
252247
Future<void> _parseLibraries(
253248
void Function(DartDocResolvedLibrary) libraryAdder,
254249
Set<LibraryElement> libraries,
@@ -257,17 +252,20 @@ class PubPackageBuilder implements PackageBuilder {
257252
isLibraryIncluded ??= (_) => true;
258253
var lastPass = <PackageMeta>{};
259254
Set<PackageMeta> current;
255+
var knownParts = <String>{};
260256
do {
261257
lastPass = _packageMetasForFiles(files);
262258

263259
// Be careful here not to accidentally stack up multiple
264-
// DartDocResolvedLibrarys, as those eat our heap.
265-
for (var f in files) {
260+
// [DartDocResolvedLibrary]s, as those eat our heap.
261+
for (var f in files.difference(knownParts)) {
266262
logProgress(f);
267263
var r = await processLibrary(f);
268-
if (r != null &&
269-
!libraries.contains(r.element) &&
270-
isLibraryIncluded(r.element)) {
264+
if (r == null) {
265+
knownParts.add(f);
266+
continue;
267+
}
268+
if (!libraries.contains(r.element) && isLibraryIncluded(r.element)) {
271269
logDebug('parsing ${f}...');
272270
libraryAdder(r);
273271
libraries.add(r.element);
@@ -278,7 +276,7 @@ class PubPackageBuilder implements PackageBuilder {
278276
await driver.discoverAvailableFiles();
279277
files.addAll(driver.knownFiles);
280278
files.addAll(_includeExternalsFrom(driver.knownFiles));
281-
current = _packageMetasForFiles(files);
279+
current = _packageMetasForFiles(files.difference(knownParts));
282280
// To get canonicalization correct for non-locally documented packages
283281
// (so we can generate the right hyperlinks), it's vital that we
284282
// add all libraries in dependent packages. So if the analyzer

0 commit comments

Comments
 (0)