forked from qt-creator/qt-creator
C++ editor: Remove unnecessary line split in find usages
Avoid extra allocations since we only the actual line for the case. Change-Id: I0d0f0db394d9075bbdce24d1d5b5efa55c52f9b3 Reviewed-on: http://codereview.qt.nokia.com/261 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@nokia.com>
This commit is contained in:
committed by
Erik Verbruggen
parent
ad38a581b6
commit
83e4a7260d
@@ -44,6 +44,33 @@
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
namespace {
|
||||
|
||||
QString fetchLine(const QByteArray &bytes, const int line)
|
||||
{
|
||||
int current = 0;
|
||||
const char *s = bytes.constData();
|
||||
while (*s) {
|
||||
if (*s == '\n') {
|
||||
++current;
|
||||
if (current == line)
|
||||
break;
|
||||
}
|
||||
++s;
|
||||
}
|
||||
|
||||
if (current == line) {
|
||||
++s;
|
||||
const char *e = s;
|
||||
while (*e && *e != '\n')
|
||||
++e;
|
||||
return QString::fromUtf8(s, e - s);
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
} // Anonymous
|
||||
|
||||
FindUsages::FindUsages(const QByteArray &originalSource, Document::Ptr doc, const Snapshot &snapshot)
|
||||
: ASTVisitor(doc->translationUnit()),
|
||||
_id(0),
|
||||
@@ -167,9 +194,9 @@ void FindUsages::reportResult(unsigned tokenIndex)
|
||||
unsigned line, col;
|
||||
getTokenStartPosition(tokenIndex, &line, &col);
|
||||
QString lineText;
|
||||
QList<QByteArray> lines = _originalSource.split('\n');
|
||||
if (((int) line - 1) < lines.size())
|
||||
lineText = QString::fromUtf8(lines.at(line - 1));
|
||||
const int lines = _originalSource.count('\n') + 1;
|
||||
if (((int) line - 1) < lines)
|
||||
lineText = fetchLine(_originalSource, line - 1);
|
||||
else
|
||||
lineText = matchingLine(tk);
|
||||
|
||||
|
Reference in New Issue
Block a user