forked from qt-creator/qt-creator
CppEditor: Move static variable to function
Following the principle of scope minimization. Also, we got a reproducible crash-on-exit with MSVC with the original code. Change-Id: I465f4376fa7928de9bb878aee5faac992f75bf08 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -36,6 +36,9 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QHash>
|
||||||
|
#include <QPair>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
@@ -356,11 +359,12 @@ static QVersionNumber getClangdVersion(const FilePath &clangdFilePath)
|
|||||||
|
|
||||||
QVersionNumber ClangdSettings::clangdVersion(const FilePath &clangdFilePath)
|
QVersionNumber ClangdSettings::clangdVersion(const FilePath &clangdFilePath)
|
||||||
{
|
{
|
||||||
|
static QHash<Utils::FilePath, QPair<QDateTime, QVersionNumber>> versionCache;
|
||||||
const QDateTime timeStamp = clangdFilePath.lastModified();
|
const QDateTime timeStamp = clangdFilePath.lastModified();
|
||||||
const auto it = m_versionCache.find(clangdFilePath);
|
const auto it = versionCache.find(clangdFilePath);
|
||||||
if (it == m_versionCache.end()) {
|
if (it == versionCache.end()) {
|
||||||
const QVersionNumber version = getClangdVersion(clangdFilePath);
|
const QVersionNumber version = getClangdVersion(clangdFilePath);
|
||||||
m_versionCache.insert(clangdFilePath, qMakePair(timeStamp, version));
|
versionCache.insert(clangdFilePath, qMakePair(timeStamp, version));
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
if (it->first != timeStamp) {
|
if (it->first != timeStamp) {
|
||||||
|
@@ -29,10 +29,7 @@
|
|||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
#include <QDateTime>
|
|
||||||
#include <QHash>
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPair>
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QVersionNumber>
|
#include <QVersionNumber>
|
||||||
|
|
||||||
@@ -150,7 +147,6 @@ private:
|
|||||||
void saveSettings();
|
void saveSettings();
|
||||||
|
|
||||||
Data m_data;
|
Data m_data;
|
||||||
static inline QHash<Utils::FilePath, QPair<QDateTime, QVersionNumber>> m_versionCache;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const ClangdSettings::Data &s1, const ClangdSettings::Data &s2)
|
inline bool operator==(const ClangdSettings::Data &s1, const ClangdSettings::Data &s2)
|
||||||
|
Reference in New Issue
Block a user