Changeset View
Changeset View
Standalone View
Standalone View
src/buffer/katetexthistory.cpp
Show First 20 Lines • Show All 112 Lines • ▼ Show 20 Line(s) | 111 | { | |||
---|---|---|---|---|---|
113 | * history should never be empty | 113 | * history should never be empty | ||
114 | */ | 114 | */ | ||
115 | Q_ASSERT(!m_historyEntries.empty()); | 115 | Q_ASSERT(!m_historyEntries.empty()); | ||
116 | 116 | | |||
117 | /** | 117 | /** | ||
118 | * simple efficient check: if we only have one entry, and the entry is not referenced | 118 | * simple efficient check: if we only have one entry, and the entry is not referenced | ||
119 | * just replace it with the new one and adjust the revision | 119 | * just replace it with the new one and adjust the revision | ||
120 | */ | 120 | */ | ||
121 | if ((m_historyEntries.size() == 1) && !m_historyEntries.first().referenceCounter) { | 121 | if ((m_historyEntries.size() == 1) && !m_historyEntries.front().referenceCounter) { | ||
122 | /** | 122 | /** | ||
123 | * remember new revision for first element, it is the revision we get after this change | 123 | * remember new revision for first element, it is the revision we get after this change | ||
124 | */ | 124 | */ | ||
125 | m_firstHistoryEntryRevision = revision() + 1; | 125 | m_firstHistoryEntryRevision = revision() + 1; | ||
126 | 126 | | |||
127 | /** | 127 | /** | ||
128 | * remember edit | 128 | * remember edit | ||
129 | */ | 129 | */ | ||
130 | m_historyEntries.first() = entry; | 130 | m_historyEntries.front() = entry; | ||
131 | 131 | | |||
132 | /** | 132 | /** | ||
133 | * be done... | 133 | * be done... | ||
134 | */ | 134 | */ | ||
135 | return; | 135 | return; | ||
136 | } | 136 | } | ||
137 | 137 | | |||
138 | /** | 138 | /** | ||
139 | * ok, we have more than one entry or the entry is referenced, just add up new entries | 139 | * ok, we have more than one entry or the entry is referenced, just add up new entries | ||
140 | */ | 140 | */ | ||
141 | m_historyEntries.push_back(entry); | 141 | m_historyEntries.push_back(entry); | ||
142 | } | 142 | } | ||
143 | 143 | | |||
144 | void TextHistory::lockRevision(qint64 revision) | 144 | void TextHistory::lockRevision(qint64 revision) | ||
145 | { | 145 | { | ||
146 | /** | 146 | /** | ||
147 | * some invariants must hold | 147 | * some invariants must hold | ||
148 | */ | 148 | */ | ||
149 | Q_ASSERT(!m_historyEntries.empty()); | 149 | Q_ASSERT(!m_historyEntries.empty()); | ||
150 | Q_ASSERT(revision >= m_firstHistoryEntryRevision); | 150 | Q_ASSERT(revision >= m_firstHistoryEntryRevision); | ||
151 | Q_ASSERT(revision < (m_firstHistoryEntryRevision + m_historyEntries.size())); | 151 | Q_ASSERT(revision < (m_firstHistoryEntryRevision + qint64(m_historyEntries.size()))); | ||
152 | 152 | | |||
153 | /** | 153 | /** | ||
154 | * increment revision reference counter | 154 | * increment revision reference counter | ||
155 | */ | 155 | */ | ||
156 | Entry &entry = m_historyEntries[revision - m_firstHistoryEntryRevision]; | 156 | Entry &entry = m_historyEntries[revision - m_firstHistoryEntryRevision]; | ||
157 | ++entry.referenceCounter; | 157 | ++entry.referenceCounter; | ||
158 | } | 158 | } | ||
159 | 159 | | |||
160 | void TextHistory::unlockRevision(qint64 revision) | 160 | void TextHistory::unlockRevision(qint64 revision) | ||
161 | { | 161 | { | ||
162 | /** | 162 | /** | ||
163 | * some invariants must hold | 163 | * some invariants must hold | ||
164 | */ | 164 | */ | ||
165 | Q_ASSERT(!m_historyEntries.empty()); | 165 | Q_ASSERT(!m_historyEntries.empty()); | ||
166 | Q_ASSERT(revision >= m_firstHistoryEntryRevision); | 166 | Q_ASSERT(revision >= m_firstHistoryEntryRevision); | ||
167 | Q_ASSERT(revision < (m_firstHistoryEntryRevision + m_historyEntries.size())); | 167 | Q_ASSERT(revision < (m_firstHistoryEntryRevision + qint64(m_historyEntries.size()))); | ||
168 | 168 | | |||
169 | /** | 169 | /** | ||
170 | * decrement revision reference counter | 170 | * decrement revision reference counter | ||
171 | */ | 171 | */ | ||
172 | Entry &entry = m_historyEntries[revision - m_firstHistoryEntryRevision]; | 172 | Entry &entry = m_historyEntries[revision - m_firstHistoryEntryRevision]; | ||
173 | Q_ASSERT(entry.referenceCounter); | 173 | Q_ASSERT(entry.referenceCounter); | ||
174 | --entry.referenceCounter; | 174 | --entry.referenceCounter; | ||
175 | 175 | | |||
176 | /** | 176 | /** | ||
177 | * clean up no longer used revisions... | 177 | * clean up no longer used revisions... | ||
178 | */ | 178 | */ | ||
179 | if (!entry.referenceCounter) { | 179 | if (!entry.referenceCounter) { | ||
180 | /** | 180 | /** | ||
181 | * search for now unused stuff | 181 | * search for now unused stuff | ||
182 | */ | 182 | */ | ||
183 | int unreferencedEdits = 0; | 183 | qint64 unreferencedEdits = 0; | ||
184 | for (int i = 0; i + 1 < m_historyEntries.size(); ++i) { | 184 | for (qint64 i = 0; i + 1 < qint64(m_historyEntries.size()); ++i) { | ||
185 | if (m_historyEntries.at(i).referenceCounter) { | 185 | if (m_historyEntries[i].referenceCounter) { | ||
186 | break; | 186 | break; | ||
187 | } | 187 | } | ||
188 | 188 | | |||
189 | // remember deleted count | 189 | // remember deleted count | ||
190 | ++unreferencedEdits; | 190 | ++unreferencedEdits; | ||
191 | } | 191 | } | ||
192 | 192 | | |||
193 | /** | 193 | /** | ||
▲ Show 20 Lines • Show All 282 Lines • ▼ Show 20 Line(s) | 459 | { | |||
476 | } | 476 | } | ||
477 | 477 | | |||
478 | /** | 478 | /** | ||
479 | * some invariants must hold | 479 | * some invariants must hold | ||
480 | */ | 480 | */ | ||
481 | Q_ASSERT(!m_historyEntries.empty()); | 481 | Q_ASSERT(!m_historyEntries.empty()); | ||
482 | Q_ASSERT(fromRevision != toRevision); | 482 | Q_ASSERT(fromRevision != toRevision); | ||
483 | Q_ASSERT(fromRevision >= m_firstHistoryEntryRevision); | 483 | Q_ASSERT(fromRevision >= m_firstHistoryEntryRevision); | ||
484 | Q_ASSERT(fromRevision < (m_firstHistoryEntryRevision + m_historyEntries.size())); | 484 | Q_ASSERT(fromRevision < (m_firstHistoryEntryRevision + qint64(m_historyEntries.size()))); | ||
485 | Q_ASSERT(toRevision >= m_firstHistoryEntryRevision); | 485 | Q_ASSERT(toRevision >= m_firstHistoryEntryRevision); | ||
486 | Q_ASSERT(toRevision < (m_firstHistoryEntryRevision + m_historyEntries.size())); | 486 | Q_ASSERT(toRevision < (m_firstHistoryEntryRevision + qint64(m_historyEntries.size()))); | ||
487 | 487 | | |||
488 | /** | 488 | /** | ||
489 | * transform cursor | 489 | * transform cursor | ||
490 | */ | 490 | */ | ||
491 | bool moveOnInsert = insertBehavior == KTextEditor::MovingCursor::MoveOnInsert; | 491 | bool moveOnInsert = insertBehavior == KTextEditor::MovingCursor::MoveOnInsert; | ||
492 | 492 | | |||
493 | /** | 493 | /** | ||
494 | * forward or reverse transform? | 494 | * forward or reverse transform? | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 510 | { | |||
536 | } | 536 | } | ||
537 | 537 | | |||
538 | /** | 538 | /** | ||
539 | * some invariants must hold | 539 | * some invariants must hold | ||
540 | */ | 540 | */ | ||
541 | Q_ASSERT(!m_historyEntries.empty()); | 541 | Q_ASSERT(!m_historyEntries.empty()); | ||
542 | Q_ASSERT(fromRevision != toRevision); | 542 | Q_ASSERT(fromRevision != toRevision); | ||
543 | Q_ASSERT(fromRevision >= m_firstHistoryEntryRevision); | 543 | Q_ASSERT(fromRevision >= m_firstHistoryEntryRevision); | ||
544 | Q_ASSERT(fromRevision < (m_firstHistoryEntryRevision + m_historyEntries.size())); | 544 | Q_ASSERT(fromRevision < (m_firstHistoryEntryRevision + qint64(m_historyEntries.size()))); | ||
545 | Q_ASSERT(toRevision >= m_firstHistoryEntryRevision); | 545 | Q_ASSERT(toRevision >= m_firstHistoryEntryRevision); | ||
546 | Q_ASSERT(toRevision < (m_firstHistoryEntryRevision + m_historyEntries.size())); | 546 | Q_ASSERT(toRevision < (m_firstHistoryEntryRevision + qint64(m_historyEntries.size()))); | ||
547 | 547 | | |||
548 | /** | 548 | /** | ||
549 | * transform cursors | 549 | * transform cursors | ||
550 | */ | 550 | */ | ||
551 | 551 | | |||
552 | // first: copy cursors, without range association | 552 | // first: copy cursors, without range association | ||
553 | int startLine = range.start().line(), startColumn = range.start().column(), endLine = range.end().line(), endColumn = range.end().column(); | 553 | int startLine = range.start().line(), startColumn = range.start().column(), endLine = range.end().line(), endColumn = range.end().column(); | ||
554 | 554 | | |||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |