Commit 39d92195 authored by Michael Reeves's avatar Michael Reeves

Remove obsolete size tracking

std<list>.size() is now garenteed by c++11 to be constant time.
total size was explicitly indicated to be redudant removed.
parent e4310baf
......@@ -64,93 +64,20 @@ class MergeEditLine
bool m_bLineRemoved;
};
class MergeEditLineList : private std::list<MergeEditLine>
class MergeEditLineList :public std::list<MergeEditLine>
{ // I want to know the size immediately!
private:
typedef std::list<MergeEditLine> BASE;
int m_size;
int* m_pTotalSize;
public:
typedef std::list<MergeEditLine>::iterator iterator;
typedef std::list<MergeEditLine>::reverse_iterator reverse_iterator;
typedef std::list<MergeEditLine>::const_iterator const_iterator;
MergeEditLineList()
{
m_size = 0;
m_pTotalSize = nullptr;
}
void clear()
{
ds(-m_size);
BASE::clear();
}
void push_back(const MergeEditLine& m)
{
ds(+1);
BASE::push_back(m);
}
void push_front(const MergeEditLine& m)
{
ds(+1);
BASE::push_front(m);
}
void pop_back()
{
ds(-1);
BASE::pop_back();
}
iterator erase(iterator i)
{
ds(-1);
return BASE::erase(i);
}
iterator insert(iterator i, const MergeEditLine& m)
{
ds(+1);
return BASE::insert(i, m);
}
int size()
{
if(!m_pTotalSize) m_size = (int)BASE::size();
return m_size;
}
iterator begin() { return BASE::begin(); }
iterator end() { return BASE::end(); }
reverse_iterator rbegin() { return BASE::rbegin(); }
reverse_iterator rend() { return BASE::rend(); }
MergeEditLine& front() { return BASE::front(); }
MergeEditLine& back() { return BASE::back(); }
bool empty() { return m_size == 0; }
void splice(iterator destPos, MergeEditLineList& srcList, iterator srcFirst, iterator srcLast)
{
int* pTotalSize = getTotalSizePtr() ? getTotalSizePtr() : srcList.getTotalSizePtr();
srcList.setTotalSizePtr(nullptr); // Force size-recalc after splice, because splice doesn't handle size-tracking
setTotalSizePtr(nullptr);
BASE::splice(destPos, srcList, srcFirst, srcLast);
srcList.setTotalSizePtr(pTotalSize);
setTotalSizePtr(pTotalSize);
}
void setTotalSizePtr(int* pTotalSize)
{
if(pTotalSize == nullptr && m_pTotalSize != nullptr) { *m_pTotalSize -= size(); }
else if(pTotalSize != nullptr && m_pTotalSize == nullptr)
{
*pTotalSize += size();
}
m_pTotalSize = pTotalSize;
}
int* getTotalSizePtr()
{
return m_pTotalSize;
}
private:
void ds(int deltaSize)
int size()
{
m_size += deltaSize;
if(m_pTotalSize != nullptr) *m_pTotalSize += deltaSize;
return (int)BASE::size();
}
};
......@@ -193,7 +120,6 @@ class MergeLine
return;
}
}
ml2.mergeEditLineList.setTotalSizePtr(mergeEditLineList.getTotalSizePtr());
ml2.mergeEditLineList.push_back(MergeEditLine(ml2.id3l));
}
void join(MergeLine& ml2) // The caller must remove the ml2 from the m_mergeLineList after this call
......
......@@ -67,7 +67,6 @@ MergeResultWindow::MergeResultWindow(
m_firstLine = 0;
m_horizScrollOffset = 0;
m_nofLines = 0;
m_totalSize = 0;
m_bMyUpdate = false;
m_bInsertMode = true;
m_scrollDeltaX = 0;
......@@ -377,7 +376,7 @@ void MergeResultWindow::merge(bool bAutoSolve, e_SrcSelector defaultSelector, bo
}
m_mergeLineList.clear();
m_totalSize = 0;
int lineIdx = 0;
Diff3LineList::const_iterator it;
for(it = m_pDiff3LineList->begin(); it != m_pDiff3LineList->end(); ++it, ++lineIdx)
......@@ -412,7 +411,6 @@ void MergeResultWindow::merge(bool bAutoSolve, e_SrcSelector defaultSelector, bo
}
else
{
ml.mergeEditLineList.setTotalSizePtr(&m_totalSize);
m_mergeLineList.push_back(ml);
}
......@@ -622,7 +620,7 @@ int MergeResultWindow::getMaxTextWidth()
int MergeResultWindow::getNofLines()
{
return m_totalSize;
return m_nofLines;
}
int MergeResultWindow::getVisibleTextAreaWidth()
......@@ -1072,9 +1070,9 @@ void MergeResultWindow::choose(e_SrcSelector selector)
ml.mergeEditLineList.push_back(mel);
}
if(m_cursorYPos >= m_totalSize)
if(m_cursorYPos >= m_nofLines)
{
m_cursorYPos = m_totalSize - 1;
m_cursorYPos = m_nofLines - 1;
m_cursorXPos = 0;
}
......@@ -1913,7 +1911,7 @@ void MergeResultWindow::paintEvent(QPaintEvent*)
//int visibleLines = height() / fontHeight;
int lastVisibleLine = m_firstLine + getNofVisibleLines() + 5;
int line = 0;
LineRef line = 0;
MergeLineList::iterator mlIt = m_mergeLineList.begin();
for(mlIt = m_mergeLineList.begin(); mlIt != m_mergeLineList.end(); ++mlIt)
{
......@@ -1953,7 +1951,6 @@ void MergeResultWindow::paintEvent(QPaintEvent*)
if(line != m_nofLines)
{
m_nofLines = line;
Q_ASSERT(m_nofLines == m_totalSize);
emit resizeSignal();
}
......@@ -2037,7 +2034,7 @@ int MergeResultWindow::convertToLine(int y)
int yOffset = topLineYOffset - m_firstLine * fontHeight;
int line = std::min((y - yOffset) / fontHeight, m_totalSize - 1);
int line = std::min((y - yOffset) / fontHeight, m_nofLines - 1);
return line;
}
......@@ -2295,7 +2292,7 @@ void MergeResultWindow::keyPressEvent(QKeyEvent* e)
if(!melIt->isEditableText()) break;
if(x >= (int)str.length())
{
if(y < m_totalSize - 1)
if(y < m_nofLines - 1)
{
setModified();
MergeLineList::iterator mlIt1;
......@@ -2478,7 +2475,7 @@ void MergeResultWindow::keyPressEvent(QKeyEvent* e)
if(!bCtrl)
{
int newX = textLayoutOrig.nextCursorPosition(x);
if(newX == x && y < m_totalSize - 1)
if(newX == x && y < m_nofLines - 1)
{
++y;
x = 0;
......@@ -2575,7 +2572,7 @@ void MergeResultWindow::keyPressEvent(QKeyEvent* e)
}
}
y = qBound(0, y, m_totalSize - 1);
y = qBound(0, y, m_nofLines - 1);
calcIteratorFromLineNr(y, mlIt, melIt);
str = melIt->getString(m_pldA, m_pldB, m_pldC);
......
......@@ -205,8 +205,7 @@ private:
QPixmap m_pixmap;
int m_firstLine;
int m_horizScrollOffset;
int m_nofLines;
int m_totalSize; //Same as m_nofLines, but calculated differently
LineCount m_nofLines;
int m_maxTextWidth;
bool m_bMyUpdate;
bool m_bInsertMode;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment