From: Takashi Sawanaka Date: Sun, 8 May 2016 11:05:07 +0000 (+0900) Subject: DIFFRANGE::dbegin[] and dend[] do not need to be an array. X-Git-Tag: 2.16.4+-jp-10~720 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=432078216140be9848d8c7832023d26a07a9508d;p=winmerge-jp%2Fwinmerge-jp.git DIFFRANGE::dbegin[] and dend[] do not need to be an array. --- diff --git a/Src/DiffList.cpp b/Src/DiffList.cpp index 7d40db214..28419a1d8 100644 --- a/Src/DiffList.cpp +++ b/Src/DiffList.cpp @@ -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(nLine) < dfi->dbegin[0]) + if (static_cast(nLine) < dfi->dbegin) return -1; - else if (static_cast(nLine) > dfi->dend[0]) + else if (static_cast(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(nLine) >= dfi->dbegin[0] && static_cast(nLine) <= dfi->dend[0]) + if (static_cast(nLine) >= dfi->dbegin && static_cast(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(nLine) < DiffRangeAt(0)->dbegin[0]) + if (static_cast(nLine) < DiffRangeAt(0)->dbegin) return -1; - if (static_cast(nLine) > DiffRangeAt(nDiffCount-1)->dend[0]) + if (static_cast(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(nLine)) + if (dfi->op != OP_TRIVIAL && dfi->dend <= static_cast(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(nLine)) + if (dfi->op != OP_TRIVIAL && dfi->dbegin >= static_cast(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(nLine)) + if (dfi->op != OP_TRIVIAL && dfi->op != OP_3RDONLY && dfi->dend <= static_cast(nLine)) return i; break; case THREEWAYDIFFTYPE_LEFTRIGHT: - if (dfi->op != OP_TRIVIAL && dfi->op != OP_2NDONLY && dfi->dend[0] <= static_cast(nLine)) + if (dfi->op != OP_TRIVIAL && dfi->op != OP_2NDONLY && dfi->dend <= static_cast(nLine)) return i; break; case THREEWAYDIFFTYPE_MIDDLERIGHT: - if (dfi->op != OP_TRIVIAL && dfi->op != OP_1STONLY && dfi->dend[0] <= static_cast(nLine)) + if (dfi->op != OP_TRIVIAL && dfi->op != OP_1STONLY && dfi->dend <= static_cast(nLine)) return i; break; case THREEWAYDIFFTYPE_LEFTONLY: - if (dfi->op == OP_1STONLY && dfi->dend[0] <= static_cast(nLine)) + if (dfi->op == OP_1STONLY && dfi->dend <= static_cast(nLine)) return i; break; case THREEWAYDIFFTYPE_MIDDLEONLY: - if (dfi->op == OP_2NDONLY && dfi->dend[0] <= static_cast(nLine)) + if (dfi->op == OP_2NDONLY && dfi->dend <= static_cast(nLine)) return i; break; case THREEWAYDIFFTYPE_RIGHTONLY: - if (dfi->op == OP_3RDONLY && dfi->dend[0] <= static_cast(nLine)) + if (dfi->op == OP_3RDONLY && dfi->dend <= static_cast(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(nLine)) + if (dfi->op != OP_TRIVIAL && dfi->op != OP_3RDONLY && dfi->dbegin >= static_cast(nLine)) return i; break; case THREEWAYDIFFTYPE_LEFTRIGHT: - if (dfi->op != OP_TRIVIAL && dfi->op != OP_2NDONLY && dfi->dbegin[0] >= static_cast(nLine)) + if (dfi->op != OP_TRIVIAL && dfi->op != OP_2NDONLY && dfi->dbegin >= static_cast(nLine)) return i; break; case THREEWAYDIFFTYPE_MIDDLERIGHT: - if (dfi->op != OP_TRIVIAL && dfi->op != OP_1STONLY && dfi->dbegin[0] >= static_cast(nLine)) + if (dfi->op != OP_TRIVIAL && dfi->op != OP_1STONLY && dfi->dbegin >= static_cast(nLine)) return i; break; case THREEWAYDIFFTYPE_LEFTONLY: - if (dfi->op == OP_1STONLY && dfi->dbegin[0] >= static_cast(nLine)) + if (dfi->op == OP_1STONLY && dfi->dbegin >= static_cast(nLine)) return i; break; case THREEWAYDIFFTYPE_MIDDLEONLY: - if (dfi->op == OP_2NDONLY && dfi->dbegin[0] >= static_cast(nLine)) + if (dfi->op == OP_2NDONLY && dfi->dbegin >= static_cast(nLine)) return i; break; case THREEWAYDIFFTYPE_RIGHTONLY: - if (dfi->op == OP_3RDONLY && dfi->dbegin[0] >= static_cast(nLine)) + if (dfi->op == OP_3RDONLY && dfi->dbegin >= static_cast(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::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); } diff --git a/Src/DiffList.h b/Src/DiffList.h index d1e9e9530..761a52a46 100644 --- a/Src/DiffList.h +++ b/Src/DiffList.h @@ -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& 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 m_diffs; /**< Difference list. */ diff --git a/Src/LocationView.cpp b/Src/LocationView.cpp index 025a9e709..7aec66bec 100644 --- a/Src/LocationView.cpp +++ b/Src/LocationView.cpp @@ -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; diff --git a/Src/MergeDoc.cpp b/Src/MergeDoc.cpp index 9d8b1a30a..e94313612 100644 --- a/Src/MergeDoc.cpp +++ b/Src/MergeDoc.cpp @@ -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]) { diff --git a/Src/MergeDocLineDiffs.cpp b/Src/MergeDocLineDiffs.cpp index f52ab66d0..cdae64dff 100644 --- a/Src/MergeDocLineDiffs.cpp +++ b/Src/MergeDocLineDiffs.cpp @@ -173,34 +173,21 @@ void CMergeDoc::GetWordDiffArray(int nLineIndex, vector *pWordDiffs) String str[3]; std::unique_ptr 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 *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]) diff --git a/Src/MergeEditView.cpp b/Src/MergeEditView.cpp index d6d2d5bd5..b95a83c08 100644 --- a/Src/MergeEditView.cpp +++ b/Src/MergeEditView.cpp @@ -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