Skip to content

Commit

Permalink
In PackageBuilder._discoverLibraries, initialize newFiles outside loo…
Browse files Browse the repository at this point in the history
…p. (dart-lang#3695)

I noticed with print debugging that `addFilesReferencedBy` was being called way
too many times for a given library. It turns out this is because it was being
called on different Sets, when really it should mostly be operating on one Set.
That one Set is `newFiles`. It was initialized in the do-while loop, but it can
be initialized before the do-while loop.

I checked the logic to make sure this change is a no-op.

I also timed documenting flutter. This change seems to reduce the
time-to-document by ~100 seconds, but that is only with one before and one
after, so I promise nothing.
  • Loading branch information
srawlins committed Feb 29, 2024
1 parent 2760d25 commit 40fef4c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/src/model/package_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ class PubPackageBuilder implements PackageBuilder {
// a set of files (starting with the ones passed into the function), resolve
// them, add them to the package graph via `addLibrary`, and then discover
// which additional files need to be processed in the next loop. This
// discovery depends on various options (TODO: which?), but the basic idea
// is to take a file we've just processed, and add all of the files which
// that file references via imports or exports, and add them to the set of
// files to be processed.
// discovery depends on various options (TODO: which?). The basic idea is
// to take a file we've just processed, and add all of the files which that
// file references (via imports, augmentation imports, exports, and parts),
// and add them to the set of files to be processed.
//
// This loop may execute a few times. We know to stop looping when we have
// added zero new files to process. This is tracked with `filesInLastPass`
Expand All @@ -251,9 +251,11 @@ class PubPackageBuilder implements PackageBuilder {
if (!addingSpecials) {
progressBarStart(files.length);
}
// The set of files that are discovered while iterating in the below
// do-while loop, which are then added to `files`, as they are found.
var newFiles = <String>{};
do {
filesInLastPass = filesInCurrentPass;
var newFiles = <String>{};
if (!addingSpecials) {
progressBarUpdateTickCount(files.length);
}
Expand Down

0 comments on commit 40fef4c

Please sign in to comment.