TraceWizard.Diff.Diff.Optimize C# (CSharp) Method

Optimize() private static method

If a sequence of modified lines starts with a line that contains the same content as the line that appends the changes, the difference sequence is modified so that the appended line and not the starting line is marked as modified. This leads to more readable diff sequences when comparing text files.
private static Optimize ( DiffData Data ) : void
Data DiffData A Diff data buffer containing the identified changes.
return void
        private static void Optimize(DiffData Data)
        {
            int StartPos, EndPos;

            StartPos = 0;
            while (StartPos < Data.Length)
            {
                while ((StartPos < Data.Length) && (Data.modified[StartPos] == false))
                    StartPos++;
                EndPos = StartPos;
                while ((EndPos < Data.Length) && (Data.modified[EndPos] == true))
                    EndPos++;

                if ((EndPos < Data.Length) && (Data.data[StartPos] == Data.data[EndPos]))
                {
                    Data.modified[StartPos] = false;
                    Data.modified[EndPos] = true;
                }
                else {
                    StartPos = EndPos;
                } // if
            } // while
        } // Optimize