-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Improve RemoveDependenciesFromEntryIfMissing #5392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4007d54
edf163c
5c05c0f
0cf86a4
309e8f6
3854503
8751c30
aad17bc
0e94024
01517b5
bc4d9d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -724,6 +724,9 @@ private void RemoveDependencyFromEntry(string rootingMarker, ITaskItem dependenc | |||||||||
| /// <param name="correspondingOutputs">Outputs that correspond ot the sources (used for same file processing)</param> | ||||||||||
| public void RemoveDependenciesFromEntryIfMissing(ITaskItem[] source, ITaskItem[] correspondingOutputs) | ||||||||||
| { | ||||||||||
| // Cache of files and whether or not they exist. | ||||||||||
| Dictionary<string, bool> fileCache = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase); | ||||||||||
|
|
||||||||||
| if (correspondingOutputs != null) | ||||||||||
| { | ||||||||||
| ErrorUtilities.VerifyThrowArgument(source.Length == correspondingOutputs.Length, "Tracking_SourcesAndCorrespondingOutputMismatch"); | ||||||||||
|
|
@@ -732,29 +735,24 @@ public void RemoveDependenciesFromEntryIfMissing(ITaskItem[] source, ITaskItem[] | |||||||||
| // construct a combined root marker for the sources and outputs to remove from the graph | ||||||||||
| string rootingMarker = FileTracker.FormatRootingMarker(source, correspondingOutputs); | ||||||||||
|
|
||||||||||
| RemoveDependenciesFromEntryIfMissing(rootingMarker); | ||||||||||
| RemoveDependenciesFromEntryIfMissing(rootingMarker, fileCache); | ||||||||||
|
|
||||||||||
| // Remove entries for each individual source | ||||||||||
| for (int sourceIndex = 0; sourceIndex < source.Length; sourceIndex++) | ||||||||||
| { | ||||||||||
| if (correspondingOutputs != null) | ||||||||||
| { | ||||||||||
| rootingMarker = FileTracker.FormatRootingMarker(source[sourceIndex], correspondingOutputs[sourceIndex]); | ||||||||||
| } | ||||||||||
| else | ||||||||||
| { | ||||||||||
| rootingMarker = FileTracker.FormatRootingMarker(source[sourceIndex]); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| RemoveDependenciesFromEntryIfMissing(rootingMarker); | ||||||||||
| rootingMarker = correspondingOutputs != null | ||||||||||
| ? FileTracker.FormatRootingMarker(source[sourceIndex], correspondingOutputs[sourceIndex]) | ||||||||||
| : FileTracker.FormatRootingMarker(source[sourceIndex]); | ||||||||||
|
Comment on lines
+743
to
+745
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't take this suggestion, it causes a nullreferenceexception.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, what? This should never be passing an array, just null or the value of the array. Did you miss the '?'?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you may be mistaken as to which overload gets called here. There are two overloads that are very similar: The suggested change calls the first overload, which packs both items into arrays like so: Then calls the second overload which eventually does this: Notice it does a null check on the array, not the items within. and the second foreach loop will break because it tries to get the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I understand why the change could be problematic, but now I don't understand why your version would work. In any case, it's the same as it had been before, and the change wasn't really an optimization anyway, so I'm not going to block on this. |
||||||||||
| RemoveDependenciesFromEntryIfMissing(rootingMarker, fileCache); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /// <summary> | ||||||||||
| /// Remove the output graph entries for the given rooting marker | ||||||||||
| /// </summary> | ||||||||||
| /// <param name="rootingMarker"></param> | ||||||||||
| private void RemoveDependenciesFromEntryIfMissing(string rootingMarker) | ||||||||||
| /// <param name="fileCache">The cache used to store whether each file exists or not.</param> | ||||||||||
| private void RemoveDependenciesFromEntryIfMissing(string rootingMarker, Dictionary<string, bool> fileCache) | ||||||||||
| { | ||||||||||
| // In the event of incomplete tracking information (i.e. this root was not present), just continue quietly | ||||||||||
| // as the user could have killed the tool being tracked, or another error occurred during its execution. | ||||||||||
|
|
@@ -767,8 +765,19 @@ private void RemoveDependenciesFromEntryIfMissing(string rootingMarker) | |||||||||
| { | ||||||||||
| if (keyIndex++ > 0) | ||||||||||
| { | ||||||||||
| // If we are ignoring missing files, then only record those that exist | ||||||||||
| if (FileUtilities.FileExistsNoThrow(file)) | ||||||||||
| // Record whether or not each file exists and cache it. | ||||||||||
| // We do this to save time (On^2), at the expense of data O(n). | ||||||||||
| bool inFileCache = fileCache.TryGetValue(file, out bool fileExists); | ||||||||||
|
|
||||||||||
| // Have we cached the file yet? If not, cache its existence. | ||||||||||
| if (!inFileCache) | ||||||||||
| { | ||||||||||
| fileExists = FileUtilities.FileExistsNoThrow(file); | ||||||||||
| fileCache.Add(file, fileExists); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Does the cached file exist? | ||||||||||
| if (fileExists) | ||||||||||
| { | ||||||||||
| dependenciesWithoutMissingFiles.Add(file, dependencies[file]); | ||||||||||
| } | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.