Skip to content

Commit

Permalink
short circuit BuildPieceHashes
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored and mmanela committed Jul 13, 2024
1 parent 6068ce9 commit 015abba
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions DiffPlex/Differ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ namespace DiffPlex
{
public class Differ : IDiffer
{

private static readonly string[] emptyStringArray = new string[0];

/// <summary>
/// Gets the default singleton instance of differ instance.
/// </summary>
Expand Down Expand Up @@ -328,10 +325,15 @@ private static void BuildModificationData

private static void BuildPieceHashes(IDictionary<string, int> pieceHash, ModificationData data, bool ignoreWhitespace, IChunker chunker)
{
var pieces = string.IsNullOrEmpty(data.RawData)
? emptyStringArray
: chunker.Chunk(data.RawData);
if (string.IsNullOrEmpty(data.RawData))
{
data.Pieces = [];
data.HashedPieces = [];
data.Modifications = [];
return;
}

var pieces = chunker.Chunk(data.RawData);
data.Pieces = pieces;
data.HashedPieces = new int[pieces.Count];
data.Modifications = new bool[pieces.Count];
Expand All @@ -351,6 +353,7 @@ private static void BuildPieceHashes(IDictionary<string, int> pieceHash, Modific
pieceHash[piece] = pieceHash.Count;
}
}

}
}
}

0 comments on commit 015abba

Please sign in to comment.