diff options
author | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-06-28 10:16:48 +0200 |
---|---|---|
committer | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-06-28 12:50:34 +0000 |
commit | be3e848c0f1aa6654362c5c2dacf5d5895ccffcd (patch) | |
tree | 664853bc70cc1b65841406b33749d7d04823d95c /src | |
parent | 66a271a150a9be8f8e67e9aa4b4d01a2c583866a (diff) |
Clang: Don't analyze same file multiple times
Diagnostics do not depend much on project parts. But
having the same file twice can result in duplicated
diagnostics which later can cause the same fix-it
being applied twice and getting corrupted code.
Change-Id: Ie2809af7a54034b05df9383875f7c3123aea58e8
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/clangtools/clangfileinfo.h | 14 | ||||
-rw-r--r-- | src/plugins/clangtools/clangselectablefilesdialog.cpp | 6 | ||||
-rw-r--r-- | src/plugins/clangtools/clangtidyclazytool.cpp | 2 | ||||
-rw-r--r-- | src/plugins/clangtools/clangtool.cpp | 4 |
4 files changed, 19 insertions, 7 deletions
diff --git a/src/plugins/clangtools/clangfileinfo.h b/src/plugins/clangtools/clangfileinfo.h index a543ca1f27..735028a1f9 100644 --- a/src/plugins/clangtools/clangfileinfo.h +++ b/src/plugins/clangtools/clangfileinfo.h @@ -36,12 +36,24 @@ namespace Internal { class FileInfo { public: + FileInfo() = default; + FileInfo(Utils::FileName file, + CppTools::ProjectFile::Kind kind, + CppTools::ProjectPart::Ptr projectPart) + : file(std::move(file)) + , kind(kind) + , projectPart(projectPart) + {} Utils::FileName file; CppTools::ProjectFile::Kind kind; CppTools::ProjectPart::Ptr projectPart; }; -using FileInfos = QVector<FileInfo>; +inline bool operator==(const FileInfo &lhs, const FileInfo &rhs) { + return lhs.file == rhs.file; +} + +using FileInfos = std::vector<FileInfo>; } // namespace Internal } // namespace ClangTools diff --git a/src/plugins/clangtools/clangselectablefilesdialog.cpp b/src/plugins/clangtools/clangselectablefilesdialog.cpp index e9cdc42625..08ba746553 100644 --- a/src/plugins/clangtools/clangselectablefilesdialog.cpp +++ b/src/plugins/clangtools/clangselectablefilesdialog.cpp @@ -155,7 +155,7 @@ public: return false; if (!node->isDir) - result += static_cast<TreeWithFileInfo *>(node)->info; + result.push_back(static_cast<TreeWithFileInfo *>(node)->info); return true; }); @@ -194,7 +194,7 @@ private: Tree *projectDirTree = buildProjectDirTree(project->projectDirectory(), fileInfos, outOfBaseDirFiles); - if (outOfBaseDirFiles.isEmpty()) { + if (outOfBaseDirFiles.empty()) { // Showing the project file and beneath the project dir is pointless in this case, // so get rid of the root node and modify the project dir node as the new root node. projectDirTree->name = m_root->name; @@ -229,7 +229,7 @@ private: for (const FileInfo &fileInfo : fileInfos) { if (!fileInfo.file.isChildOf(projectDirNode->fullPath)) { - outOfBaseDirFiles += fileInfo; + outOfBaseDirFiles.push_back(fileInfo); continue; // Handle these separately. } diff --git a/src/plugins/clangtools/clangtidyclazytool.cpp b/src/plugins/clangtools/clangtidyclazytool.cpp index 2c74837125..d3f3d841b7 100644 --- a/src/plugins/clangtools/clangtidyclazytool.cpp +++ b/src/plugins/clangtools/clangtidyclazytool.cpp @@ -333,7 +333,7 @@ void ClangTidyClazyTool::startTool(bool askUserForFileSelection) QTC_ASSERT(project, return); const FileInfos fileInfos = collectFileInfos(project, askUserForFileSelection); - if (fileInfos.isEmpty()) + if (fileInfos.empty()) return; auto clangTool = new ClangTidyClazyRunControl(runControl, diff --git a/src/plugins/clangtools/clangtool.cpp b/src/plugins/clangtools/clangtool.cpp index 7c63fa4ee4..248bee44ea 100644 --- a/src/plugins/clangtools/clangtool.cpp +++ b/src/plugins/clangtools/clangtool.cpp @@ -78,13 +78,13 @@ static FileInfos sortedFileInfos(const QVector<CppTools::ProjectPart::Ptr> &proj continue; if (CppTools::ProjectFile::isSource(file.kind)) { - const FileInfo info{Utils::FileName::fromString(file.path), file.kind, projectPart}; - fileInfos.append(info); + fileInfos.emplace_back(Utils::FileName::fromString(file.path), file.kind, projectPart); } } } Utils::sort(fileInfos, &FileInfo::file); + fileInfos.erase(std::unique(fileInfos.begin(), fileInfos.end()), fileInfos.end()); return fileInfos; } |