From 015abbacef6d91e5fb4e7bd0788c2568735f07b0 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sat, 13 Jul 2024 17:29:37 +1000 Subject: [PATCH] short circuit BuildPieceHashes --- DiffPlex/Differ.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/DiffPlex/Differ.cs b/DiffPlex/Differ.cs index 034108d..281ee96 100644 --- a/DiffPlex/Differ.cs +++ b/DiffPlex/Differ.cs @@ -7,9 +7,6 @@ namespace DiffPlex { public class Differ : IDiffer { - - private static readonly string[] emptyStringArray = new string[0]; - /// /// Gets the default singleton instance of differ instance. /// @@ -328,10 +325,15 @@ private static void BuildModificationData private static void BuildPieceHashes(IDictionary 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]; @@ -351,6 +353,7 @@ private static void BuildPieceHashes(IDictionary pieceHash, Modific pieceHash[piece] = pieceHash.Count; } } + } } } \ No newline at end of file