Skip to content

Commit 32f6cca

Browse files
committed
Don't provide a diff notify callback unless necessary
We only seem to care about what ends up being collected in the `MatchedPathsAggregator` when we've got some file paths to match agains and either an `OnUnmatchedPath` delegate or instructions to throw on unmatched paths. If none of those condition are true we shouldn't be sending a callback function pointer at all and by not doing so we avoid one marshalled invocation per delta in the diff.
1 parent 45846e2 commit 32f6cca

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

LibGit2Sharp/Diff.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,25 @@ private DiffSafeHandle BuildDiffList(
516516
ExplicitPathsOptions explicitPathsOptions,
517517
CompareOptions compareOptions)
518518
{
519-
var matchedPaths = new MatchedPathsAggregator();
520519
var filePaths = repo.ToFilePaths(paths);
521520

521+
MatchedPathsAggregator matchedPaths = null;
522+
523+
// We can't match paths unless we've got something to match
524+
// against and we're told to do so.
525+
if (filePaths != null && explicitPathsOptions != null)
526+
{
527+
if (explicitPathsOptions.OnUnmatchedPath != null || explicitPathsOptions.ShouldFailOnUnmatchedPath)
528+
{
529+
matchedPaths = new MatchedPathsAggregator();
530+
}
531+
}
532+
522533
using (GitDiffOptions options = BuildOptions(diffOptions, filePaths, matchedPaths, compareOptions))
523534
{
524535
var diffList = comparisonHandleRetriever(oldTreeId, newTreeId, options);
525536

526-
if (explicitPathsOptions != null)
537+
if (matchedPaths != null)
527538
{
528539
try
529540
{

0 commit comments

Comments
 (0)