diff options
| author | Leandro Melo <[email protected]> | 2011-05-31 11:57:00 +0200 |
|---|---|---|
| committer | Erik Verbruggen <[email protected]> | 2011-05-31 12:08:17 +0200 |
| commit | 83e4a7260dd4131b0028ab3d8fa1bd51bc0e55f7 (patch) | |
| tree | c10b6a694f879501b386a9dd9f40bc3dd090185f /src/libs/cplusplus/FindUsages.cpp | |
| parent | ad38a581b68f1f2f84343c294454c6da80df963a (diff) | |
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 <[email protected]>
Reviewed-by: Erik Verbruggen <[email protected]>
Diffstat (limited to 'src/libs/cplusplus/FindUsages.cpp')
| -rw-r--r-- | src/libs/cplusplus/FindUsages.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp index 7c4f75d5584..95aa41221ae 100644 --- a/src/libs/cplusplus/FindUsages.cpp +++ b/src/libs/cplusplus/FindUsages.cpp @@ -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); |
