OSDN Git Service

DIFFRANGE::dbegin[] and dend[] do not need to be an array.
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 8 May 2016 11:05:07 +0000 (20:05 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 8 May 2016 11:05:07 +0000 (20:05 +0900)
Src/DiffList.cpp
Src/DiffList.h
Src/LocationView.cpp
Src/MergeDoc.cpp
Src/MergeDocLineDiffs.cpp
Src/MergeEditView.cpp

index 7d40db2..28419a1 100644 (file)
@@ -36,8 +36,6 @@ void DIFFRANGE::swap_sides(int index1, int index2)
 {
        swap(begin[index1], begin[index2]);
        swap(end[index1], end[index2]);
-       swap(dbegin[index1], dbegin[index2]);
-       swap(dend[index1], dend[index2]);
        swap(blank[index1], blank[index2]);
 }
 
@@ -249,9 +247,9 @@ bool DiffList::SetDiff(int nDiff, const DIFFRANGE & di)
 int DiffList::LineRelDiff(int nLine, int nDiff) const
 {
        const DIFFRANGE * dfi = DiffRangeAt(nDiff);
-       if (static_cast<int>(nLine) < dfi->dbegin[0])
+       if (static_cast<int>(nLine) < dfi->dbegin)
                return -1;
-       else if (static_cast<int>(nLine) > dfi->dend[0])
+       else if (static_cast<int>(nLine) > dfi->dend)
                return 1;
        else
                return 0;
@@ -266,7 +264,7 @@ int DiffList::LineRelDiff(int nLine, int nDiff) const
 bool DiffList::LineInDiff(int nLine, int nDiff) const
 {
        const DIFFRANGE * dfi = DiffRangeAt(nDiff);
-       if (static_cast<int>(nLine) >= dfi->dbegin[0] && static_cast<int>(nLine) <= dfi->dend[0])
+       if (static_cast<int>(nLine) >= dfi->dbegin && static_cast<int>(nLine) <= dfi->dend)
                return true;
        else
                return false;
@@ -284,9 +282,9 @@ int DiffList::LineToDiff(int nLine) const
                return -1;
 
        // First check line is not before first or after last diff
-       if (static_cast<int>(nLine) < DiffRangeAt(0)->dbegin[0])
+       if (static_cast<int>(nLine) < DiffRangeAt(0)->dbegin)
                return -1;
-       if (static_cast<int>(nLine) > DiffRangeAt(nDiffCount-1)->dend[0])
+       if (static_cast<int>(nLine) > DiffRangeAt(nDiffCount-1)->dend)
                return -1;
 
        // Use binary search to search for a diff.
@@ -338,7 +336,7 @@ bool DiffList::GetPrevDiff(int nLine, int & nDiff) const
                const int size = (int) m_diffs.size();
                for (int i = (int) size - 1; i >= 0 ; i--)
                {
-                       if ((int)DiffRangeAt(i)->dend[0] <= nLine)
+                       if ((int)DiffRangeAt(i)->dend <= nLine)
                        {
                                numDiff = i;
                                break;
@@ -370,7 +368,7 @@ bool DiffList::GetNextDiff(int nLine, int & nDiff) const
                const int nDiffCount = (int) m_diffs.size();
                for (int i = 0; i < nDiffCount; i++)
                {
-                       if ((int)DiffRangeAt(i)->dbegin[0] >= nLine)
+                       if ((int)DiffRangeAt(i)->dbegin >= nLine)
                        {
                                numDiff = i;
                                break;
@@ -405,7 +403,7 @@ int DiffList::PrevSignificantDiffFromLine(int nLine) const
        for (int i = size - 1; i >= 0 ; i--)
        {
                const DIFFRANGE * dfi = DiffRangeAt(i);
-               if (dfi->op != OP_TRIVIAL && dfi->dend[0] <= static_cast<int>(nLine))
+               if (dfi->op != OP_TRIVIAL && dfi->dend <= static_cast<int>(nLine))
                {
                        nDiff = i;
                        break;
@@ -427,7 +425,7 @@ int DiffList::NextSignificantDiffFromLine(int nLine) const
        for (size_t i = 0; i < nDiffCount; i++)
        {
                const DIFFRANGE * dfi = DiffRangeAt(i);
-               if (dfi->op != OP_TRIVIAL && dfi->dbegin[0] >= static_cast<int>(nLine))
+               if (dfi->op != OP_TRIVIAL && dfi->dbegin >= static_cast<int>(nLine))
                {
                        nDiff = i;
                        break;
@@ -591,31 +589,31 @@ int DiffList::PrevSignificant3wayDiffFromLine(int nLine, int nDiffType) const
                switch (nDiffType)
                {
                case THREEWAYDIFFTYPE_LEFTMIDDLE:
-                       if (dfi->op != OP_TRIVIAL && dfi->op != OP_3RDONLY && dfi->dend[0] <= static_cast<int>(nLine))
+                       if (dfi->op != OP_TRIVIAL && dfi->op != OP_3RDONLY && dfi->dend <= static_cast<int>(nLine))
                                return i;
                        break;
                case THREEWAYDIFFTYPE_LEFTRIGHT:
-                       if (dfi->op != OP_TRIVIAL && dfi->op != OP_2NDONLY && dfi->dend[0] <= static_cast<int>(nLine))
+                       if (dfi->op != OP_TRIVIAL && dfi->op != OP_2NDONLY && dfi->dend <= static_cast<int>(nLine))
                                return i;
                        break;
                case THREEWAYDIFFTYPE_MIDDLERIGHT:
-                       if (dfi->op != OP_TRIVIAL && dfi->op != OP_1STONLY && dfi->dend[0] <= static_cast<int>(nLine))
+                       if (dfi->op != OP_TRIVIAL && dfi->op != OP_1STONLY && dfi->dend <= static_cast<int>(nLine))
                                return i;
                        break;
                case THREEWAYDIFFTYPE_LEFTONLY:
-                       if (dfi->op == OP_1STONLY && dfi->dend[0] <= static_cast<int>(nLine))
+                       if (dfi->op == OP_1STONLY && dfi->dend <= static_cast<int>(nLine))
                                return i;
                        break;
                case THREEWAYDIFFTYPE_MIDDLEONLY:
-                       if (dfi->op == OP_2NDONLY && dfi->dend[0] <= static_cast<int>(nLine))
+                       if (dfi->op == OP_2NDONLY && dfi->dend <= static_cast<int>(nLine))
                                return i;
                        break;
                case THREEWAYDIFFTYPE_RIGHTONLY:
-                       if (dfi->op == OP_3RDONLY && dfi->dend[0] <= static_cast<int>(nLine))
+                       if (dfi->op == OP_3RDONLY && dfi->dend <= static_cast<int>(nLine))
                                return i;
                        break;
                case THREEWAYDIFFTYPE_CONFLICT:
-                       if (dfi->op == OP_DIFF && dfi->dend[0] <= nLine)
+                       if (dfi->op == OP_DIFF && dfi->dend <= nLine)
                                return i;
                        break;
                }
@@ -638,31 +636,31 @@ int DiffList::NextSignificant3wayDiffFromLine(int nLine, int nDiffType) const
                switch (nDiffType)
                {
                case THREEWAYDIFFTYPE_LEFTMIDDLE:
-                       if (dfi->op != OP_TRIVIAL && dfi->op != OP_3RDONLY && dfi->dbegin[0] >= static_cast<int>(nLine))
+                       if (dfi->op != OP_TRIVIAL && dfi->op != OP_3RDONLY && dfi->dbegin >= static_cast<int>(nLine))
                                return i;
                        break;
                case THREEWAYDIFFTYPE_LEFTRIGHT:
-                       if (dfi->op != OP_TRIVIAL && dfi->op != OP_2NDONLY && dfi->dbegin[0] >= static_cast<int>(nLine))
+                       if (dfi->op != OP_TRIVIAL && dfi->op != OP_2NDONLY && dfi->dbegin >= static_cast<int>(nLine))
                                return i;
                        break;
                case THREEWAYDIFFTYPE_MIDDLERIGHT:
-                       if (dfi->op != OP_TRIVIAL && dfi->op != OP_1STONLY && dfi->dbegin[0] >= static_cast<int>(nLine))
+                       if (dfi->op != OP_TRIVIAL && dfi->op != OP_1STONLY && dfi->dbegin >= static_cast<int>(nLine))
                                return i;
                        break;
                case THREEWAYDIFFTYPE_LEFTONLY:
-                       if (dfi->op == OP_1STONLY && dfi->dbegin[0] >= static_cast<int>(nLine))
+                       if (dfi->op == OP_1STONLY && dfi->dbegin >= static_cast<int>(nLine))
                                return i;
                        break;
                case THREEWAYDIFFTYPE_MIDDLEONLY:
-                       if (dfi->op == OP_2NDONLY && dfi->dbegin[0] >= static_cast<int>(nLine))
+                       if (dfi->op == OP_2NDONLY && dfi->dbegin >= static_cast<int>(nLine))
                                return i;
                        break;
                case THREEWAYDIFFTYPE_RIGHTONLY:
-                       if (dfi->op == OP_3RDONLY && dfi->dbegin[0] >= static_cast<int>(nLine))
+                       if (dfi->op == OP_3RDONLY && dfi->dbegin >= static_cast<int>(nLine))
                                return i;
                        break;
                case THREEWAYDIFFTYPE_CONFLICT:
-                       if (dfi->op == OP_DIFF && dfi->dbegin[0] >= nLine)
+                       if (dfi->op == OP_DIFF && dfi->dbegin >= nLine)
                                return i;
                        break;
                }
@@ -924,7 +922,7 @@ void DiffList::GetExtraLinesCounts(int nFiles, int extras[])
        }
 }
 
-void DiffList::AppendDiffList(const DiffList& list, int offset[], int doffset[])
+void DiffList::AppendDiffList(const DiffList& list, int offset[], int doffset)
 {
        for (std::vector<DiffRangeInfo>::const_iterator it = list.m_diffs.begin(); it != list.m_diffs.end(); ++it)
        {
@@ -937,10 +935,12 @@ void DiffList::AppendDiffList(const DiffList& list, int offset[], int doffset[])
                                dr.end[file] += offset[file];
                        }
                        if (doffset)
-                       {
-                               dr.dbegin[file] += doffset[file];
-                               dr.dend[file] += doffset[file];
-                       }
+                               dr.blank[file] += doffset;
+               }
+               if (doffset)
+               {
+                       dr.dbegin += doffset;
+                       dr.dend += doffset;
                }
                AddDiff(dr);
        }
index d1e9e95..761a52a 100644 (file)
@@ -65,8 +65,8 @@ struct DIFFRANGE
 {
        int begin[3];   /**< First diff line in original file1,2,3 */
        int end[3];     /**< Last diff line in original file1,2,3 */
-       int dbegin[3];  /**< Synchronised (ghost lines added) first diff line in file1,2,3 */
-       int dend[3];    /**< Synchronised (ghost lines added) last diff line in file1,2,3 */
+       int dbegin;     /**< Synchronised (ghost lines added) first diff line in file1,2,3 */
+       int dend;       /**< Synchronised (ghost lines added) last diff line in file1,2,3 */
        int blank[3];           /**< Number of blank lines in file1,2,3 */
        OP_TYPE op;             /**< Operation done with this diff */
        DIFFRANGE()
@@ -171,7 +171,7 @@ public:
 
        std::vector<DiffRangeInfo>& GetDiffRangeInfoVector() { return m_diffs; }
 
-       void AppendDiffList(const DiffList& list, int offset[] = NULL, int doffset[] = NULL);
+       void AppendDiffList(const DiffList& list, int offset[] = NULL, int doffset = 0);
 
 private:
        std::vector<DiffRangeInfo> m_diffs; /**< Difference list. */
index 025a9e7..7aec66b 100644 (file)
@@ -285,7 +285,7 @@ void CLocationView::CalculateBlocks()
                int bs[4] = {0};
                int minY = INT_MAX, maxY = -1;
 
-               bs[nBlocks++] = diff.dbegin[0];
+               bs[nBlocks++] = diff.dbegin;
                for (i = 0; i < pDoc->m_nBuffers; i++)
                {
                        if (diff.blank[i] >= 0)
@@ -305,7 +305,7 @@ void CLocationView::CalculateBlocks()
                        bs[nBlocks++] = minY;
                        bs[nBlocks++] = maxY;
                }
-               bs[nBlocks] = diff.dend[0] + 1;
+               bs[nBlocks] = diff.dend + 1;
                if (bs[nBlocks] >= nLineCount)
                        bs[nBlocks] = nLineCount - 1;
 
index 9d8b1a3..e943136 100644 (file)
@@ -872,12 +872,12 @@ void CMergeDoc::CopyMultipleList(int srcPane, int dstPane, int firstDiff, int la
                {
                        SetCurrentDiff(i);
                        const DIFFRANGE *pdi = m_diffList.DiffRangeAt(i);
-                       if (currentPosDst.y > pdi->dend[dstPane])
+                       if (currentPosDst.y > pdi->dend)
                        {
                                if (pdi->blank[dstPane] >= 0)
-                                       currentPosDst.y -= pdi->dend[dstPane] - pdi->blank[dstPane] + 1;
+                                       currentPosDst.y -= pdi->dend - pdi->blank[dstPane] + 1;
                                else if (pdi->blank[srcPane] >= 0)
-                                       currentPosDst.y -= pdi->dend[dstPane] - pdi->blank[srcPane] + 1;
+                                       currentPosDst.y -= pdi->dend - pdi->blank[srcPane] + 1;
                        }                       
                        // Group merge with previous (merge undo data to one action)
                        bGroupWithPrevious = true;
@@ -985,12 +985,12 @@ void CMergeDoc::DoAutoMerge(int dstPane)
                if (srcPane != -1)
                {
                        SetCurrentDiff(i);
-                       if (currentPosDst.y > pdi->dend[dstPane])
+                       if (currentPosDst.y > pdi->dend)
                        {
                                if (pdi->blank[dstPane] >= 0)
-                                       currentPosDst.y -= pdi->dend[dstPane] - pdi->blank[dstPane] + 1;
+                                       currentPosDst.y -= pdi->dend - pdi->blank[dstPane] + 1;
                                else if (pdi->blank[srcPane] >= 0)
-                                       currentPosDst.y -= pdi->dend[dstPane] - pdi->blank[srcPane] + 1;
+                                       currentPosDst.y -= pdi->dend - pdi->blank[srcPane] + 1;
                        }                       
                        // Group merge with previous (merge undo data to one action)
                        if (!ListCopy(srcPane, dstPane, -1, bGroupWithPrevious, false))
@@ -1042,8 +1042,8 @@ void CMergeDoc::DoAutoMerge(int dstPane)
  */
 bool CMergeDoc::SanityCheckDiff(DIFFRANGE dr) const
 {
-       const int cd_dbegin = dr.dbegin[0];
-       const int cd_dend = dr.dend[0];
+       const int cd_dbegin = dr.dbegin;
+       const int cd_dend = dr.dend;
        int nBuffer;
 
        // Must ensure line number is in range before getting line flags
@@ -1126,8 +1126,8 @@ bool CMergeDoc::ListCopy(int srcPane, int dstPane, int nDiff /* = -1*/,
                CDiffTextBuffer& sbuf = *m_ptBuf[srcPane];
                CDiffTextBuffer& dbuf = *m_ptBuf[dstPane];
                bool bSrcWasMod = sbuf.IsModified();
-               const int cd_dbegin = cd.dbegin[srcPane];
-               const int cd_dend = cd.dend[srcPane];
+               const int cd_dbegin = cd.dbegin;
+               const int cd_dend = cd.dend;
                const int cd_blank = cd.blank[srcPane];
                bool bInSync = SanityCheckDiff(cd);
 
@@ -1999,9 +1999,9 @@ void CMergeDoc::PrimeTextBuffers()
 
                        lcount[file] -= nline[file];
 
-                       // set dbegin, dend, blank, and line flags
-                       curDiff.dbegin[file] = lcountnew[file];
                }
+               // set dbegin, dend, blank, and line flags
+               curDiff.dbegin = lcountnew[0];
 
                switch (curDiff.op)
                {
@@ -2014,15 +2014,15 @@ void CMergeDoc::PrimeTextBuffers()
                case OP_3RDONLY:
                        // set curdiff
                        {
+                               curDiff.dend = lcountnew[0]+nmaxline-1;
                                for (file = 0; file < m_nBuffers; file++)
                                {
-                                       curDiff.dend[file] = lcountnew[file]+nmaxline-1;
                                        curDiff.blank[file] = -1;
                                        int nextra = nmaxline - nline[file];
                                        if (nmaxline > nline[file])
                                        {
                                                // more lines on left, ghost lines on right side
-                                               curDiff.blank[file] = curDiff.dend[file]+1 - nextra;
+                                               curDiff.blank[file] = curDiff.dend + 1 - nextra;
                                        }
                                }
                        }
@@ -2032,7 +2032,7 @@ void CMergeDoc::PrimeTextBuffers()
                                {
                                        // left side
                                        int i;
-                                       for (i = curDiff.dbegin[file]; i <= curDiff.dend[file] ; i++)
+                                       for (i = curDiff.dbegin; i <= curDiff.dend; i++)
                                        {
                                                if (curDiff.blank[file] == -1 || (int)i < curDiff.blank[file])
                                                {
index f52ab66..cdae64d 100644 (file)
@@ -173,34 +173,21 @@ void CMergeDoc::GetWordDiffArray(int nLineIndex, vector<WordDiff> *pWordDiffs)
        String str[3];
        std::unique_ptr<int[]> nOffsets[3];
        const int LineLimit = 20;
-       bool diffPerLine = false;
-       
-       for (file = 0; file < m_nBuffers; file++)
+       bool diffPerLine = (cd.dend - cd.dbegin > LineLimit) ? true : false;
+
+       int nLineBegin, nLineEnd;
+       if (!diffPerLine)
        {
-               if (cd.dend[file] - cd.dbegin[file] > LineLimit)
-               {
-                       diffPerLine = true;
-                       break;
-               }
+               nLineBegin = cd.dbegin;
+               nLineEnd = cd.dend;
        }
-
-       int nLineBegins[3], nLineEnds[3];
-       for (file = 0; file < m_nBuffers; file++)
+       else
        {
-               if (!diffPerLine)
-               {
-                       nLineBegins[file] = cd.dbegin[file];
-                       nLineEnds[file] = cd.dend[file];
-               }
-               else
-               {
-                       nLineBegins[file] = nLineEnds[file] = nLineIndex;
-               }
+               nLineBegin = nLineEnd = nLineIndex;
        }
 
        for (file = 0; file < m_nBuffers; file++)
        {
-               int nLineBegin = nLineBegins[file], nLineEnd = nLineEnds[file];
                nOffsets[file].reset(new int[nLineEnd - nLineBegin + 1]);
                CString strText;
                if (nLineBegin != nLineEnd || m_ptBuf[file]->GetLineLength(nLineEnd) > 0)
@@ -231,7 +218,6 @@ void CMergeDoc::GetWordDiffArray(int nLineIndex, vector<WordDiff> *pWordDiffs)
                for (file = 0; file < m_nBuffers; file++)
                {
                        int nLine;
-                       int nLineBegin = nLineBegins[file], nLineEnd = nLineEnds[file];
                        for (nLine = nLineBegin; nLine < nLineEnd; nLine++)
                        {
                                if (it->begin[file] == nOffsets[file][nLine-nLineBegin] || it->begin[file] < nOffsets[file][nLine-nLineBegin+1])
index d6d2d5b..b95a83c 100644 (file)
@@ -328,7 +328,7 @@ void CMergeEditView::GetFullySelectedDiffs(int & firstDiff, int & lastDiff)
                
                // Check that first selected line is first diff's first line or above it
                VERIFY(pd->m_diffList.GetDiff(firstDiff, di));
-               if ((int)di.dbegin[0] < firstLine)
+               if ((int)di.dbegin < firstLine)
                {
                        if (firstDiff < lastDiff)
                                ++firstDiff;
@@ -336,7 +336,7 @@ void CMergeEditView::GetFullySelectedDiffs(int & firstDiff, int & lastDiff)
 
                // Check that last selected line is last diff's last line or below it
                VERIFY(pd->m_diffList.GetDiff(lastDiff, di));
-               if ((int)di.dend[0] > lastLine)
+               if ((int)di.dend > lastLine)
                {
                        if (firstDiff < lastDiff)
                                --lastDiff;
@@ -760,9 +760,9 @@ void CMergeEditView::OnDisplayDiff(int nDiff /*=0*/)
                DIFFRANGE curDiff;
                VERIFY(pd->m_diffList.GetDiff(nDiff, curDiff));
 
-               newlineBegin = curDiff.dbegin[0];
+               newlineBegin = curDiff.dbegin;
                ASSERT (newlineBegin >= 0);
-               newlineEnd = curDiff.dend[0];
+               newlineEnd = curDiff.dend;
        }
 
        if (newlineBegin == m_lineBegin && newlineEnd == m_lineEnd)
@@ -1164,7 +1164,7 @@ void CMergeEditView::OnUpdateNextdiff(CCmdUI* pCmdUI)
        {
                // Enable if the beginning of the last significant difference is after caret
                CPoint pos = GetCursorPos();
-               pCmdUI->Enable(pos.y < (long)dfi->dbegin[0]);
+               pCmdUI->Enable(pos.y < (long)dfi->dbegin);
        }
 }
 
@@ -1248,7 +1248,7 @@ void CMergeEditView::OnUpdatePrevdiff(CCmdUI* pCmdUI)
        {
                // Enable if the end of the first significant difference is before caret
                CPoint pos = GetCursorPos();
-               pCmdUI->Enable(pos.y > (long)dfi->dend[0]);
+               pCmdUI->Enable(pos.y > (long)dfi->dend);
        }
 }
 
@@ -1355,7 +1355,7 @@ void CMergeEditView::OnUpdateNext3wayDiff(CCmdUI* pCmdUI, int nDiffType)
        {
                // Enable if the beginning of the last significant difference is after caret
                CPoint pos = GetCursorPos();
-               pCmdUI->Enable(pos.y < (long)dfi->dbegin[0]);
+               pCmdUI->Enable(pos.y < (long)dfi->dbegin);
        }
 }
 
@@ -1437,7 +1437,7 @@ void CMergeEditView::OnUpdatePrev3wayDiff(CCmdUI* pCmdUI, int nDiffType)
        {
                // Enable if the end of the first significant difference is before caret
                CPoint pos = GetCursorPos();
-               pCmdUI->Enable(pos.y > (long)dfi->dend[0]);
+               pCmdUI->Enable(pos.y > (long)dfi->dend);
        }
 }
 
@@ -2060,9 +2060,9 @@ void CMergeEditView::ShowDiff(bool bScroll, bool bSelectText)
                pd->m_diffList.GetDiff(nDiff, curDiff);
 
                ptStart.x = 0;
-               ptStart.y = curDiff.dbegin[0];
+               ptStart.y = curDiff.dbegin;
                ptEnd.x = 0;
-               ptEnd.y = curDiff.dend[0];
+               ptEnd.y = curDiff.dend;
 
                if (bScroll)
                {
@@ -3662,10 +3662,10 @@ bool CMergeEditView::IsDiffVisible(int nDiff)
  */
 bool CMergeEditView::IsDiffVisible(const DIFFRANGE& diff, int nLinesBelow /*=0*/)
 {
-       const int nDiffStart = GetSubLineIndex(diff.dbegin[0]);
-       const int nDiffEnd = GetSubLineIndex(diff.dend[0]);
+       const int nDiffStart = GetSubLineIndex(diff.dbegin);
+       const int nDiffEnd = GetSubLineIndex(diff.dend);
        // Diff's height is last line - first line + last line's line count
-       const int nDiffHeight = nDiffEnd - nDiffStart + GetSubLines(diff.dend[0]) + 1;
+       const int nDiffHeight = nDiffEnd - nDiffStart + GetSubLines(diff.dend) + 1;
 
        // If diff first line outside current view - context OR
        // if diff last line outside current view - context OR