Commit 392bb51e authored by Luis Javier Merino's avatar Luis Javier Merino Committed by Tomaz Canabrava
Browse files

regexp filter: remember last line

RegExpFilter::process() was going through all the screen lines for every
match.  Instead, the second and next matches can start from the line
were the last match was found.
parent 64814dae
Pipeline #188534 passed with stage
in 2 minutes and 24 seconds
......@@ -34,12 +34,12 @@ void Filter::setBuffer(const QString *buffer, const QList<int> *linePositions)
_linePositions = linePositions;
}
std::pair<int, int> Filter::getLineColumn(int position)
std::pair<int, int> Filter::getLineColumn(int prevline, int position)
{
Q_ASSERT(_linePositions);
Q_ASSERT(_buffer);
for (int i = 0; i < _linePositions->count(); i++) {
for (int i = prevline; i < _linePositions->count(); i++) {
const int nextLine = i == _linePositions->count() - 1 ? _buffer->length() + 1 : _linePositions->value(i + 1);
if (_linePositions->value(i) <= position && position < nextLine) {
......
......@@ -91,7 +91,7 @@ protected:
/** Returns the internal buffer */
const QString *buffer();
/** Converts a character position within buffer() to a line and column */
std::pair<int, int> getLineColumn(int position);
std::pair<int, int> getLineColumn(int prevline, int position);
private:
Q_DISABLE_COPY(Filter)
......
......@@ -38,10 +38,13 @@ void RegExpFilter::process()
}
QRegularExpressionMatchIterator iterator(_searchText.globalMatch(*text));
int prevline = 0;
while (iterator.hasNext()) {
QRegularExpressionMatch match(iterator.next());
std::pair<int, int> start = getLineColumn(match.capturedStart());
std::pair<int, int> end = getLineColumn(match.capturedEnd());
std::pair<int, int> start = getLineColumn(prevline, match.capturedStart());
prevline = start.first;
std::pair<int, int> end = getLineColumn(prevline, match.capturedEnd());
prevline = end.first;
QSharedPointer<HotSpot> spot(newHotSpot(start.first, start.second, end.first, end.second, match.capturedTexts()));
......
Supports Markdown
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