forked from qt-creator/qt-creator
C++: cache results of linksForIdentifier in HelpItem.
The method linksForIdentifier was called at least thrice when generating a single valid tooltip in the C++ editor. Now the cached, and the cache can be "initialised" during construction. This reduces the time spent for creating a tooltip by 30%. Task-number: QTCREATORBUG-8970 Change-Id: I5130b769e977c6ffced1a87715831386ef0d5319 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
f6833168ac
commit
0f2a0d9358
@@ -77,11 +77,19 @@ void CppHoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos)
|
||||
const QSharedPointer<CppElement> &cppElement = evaluator.cppElement();
|
||||
if (!isDiagnosticTooltip())
|
||||
setToolTip(cppElement->tooltip);
|
||||
foreach (const QString &helpId, cppElement->helpIdCandidates) {
|
||||
if (!Core::HelpManager::instance()->linksForIdentifier(helpId).isEmpty()) {
|
||||
QStringList candidates = cppElement->helpIdCandidates;
|
||||
candidates.removeDuplicates();
|
||||
HelpManager *hm = HelpManager::instance();
|
||||
foreach (const QString &helpId, candidates) {
|
||||
if (helpId.isEmpty())
|
||||
continue;
|
||||
|
||||
const QMap<QString, QUrl> helpLinks = hm->linksForIdentifier(helpId);
|
||||
if (!helpLinks.isEmpty()) {
|
||||
setLastHelpItemIdentified(TextEditor::HelpItem(helpId,
|
||||
cppElement->helpMark,
|
||||
cppElement->helpCategory));
|
||||
cppElement->helpCategory,
|
||||
helpLinks));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -32,9 +32,6 @@
|
||||
#include <coreplugin/helpmanager.h>
|
||||
#include <utils/htmldocextractor.h>
|
||||
|
||||
#include <QUrl>
|
||||
#include <QMap>
|
||||
|
||||
using namespace TextEditor;
|
||||
|
||||
HelpItem::HelpItem()
|
||||
@@ -48,6 +45,11 @@ HelpItem::HelpItem(const QString &helpId, const QString &docMark, Category categ
|
||||
m_helpId(helpId), m_docMark(docMark), m_category(category)
|
||||
{}
|
||||
|
||||
HelpItem::HelpItem(const QString &helpId, const QString &docMark, Category category,
|
||||
const QMap<QString, QUrl> &helpLinks) :
|
||||
m_helpId(helpId), m_docMark(docMark), m_category(category), m_helpLinks(helpLinks)
|
||||
{}
|
||||
|
||||
HelpItem::~HelpItem()
|
||||
{}
|
||||
|
||||
@@ -71,7 +73,9 @@ HelpItem::Category HelpItem::category() const
|
||||
|
||||
bool HelpItem::isValid() const
|
||||
{
|
||||
if (!Core::HelpManager::instance()->linksForIdentifier(m_helpId).isEmpty())
|
||||
if (m_helpId.isEmpty())
|
||||
return false;
|
||||
if (!retrieveHelpLinks().isEmpty())
|
||||
return true;
|
||||
if (QUrl(m_helpId).isValid())
|
||||
return true;
|
||||
@@ -87,7 +91,7 @@ QString HelpItem::extractContent(bool extended) const
|
||||
htmlExtractor.setMode(Utils::HtmlDocExtractor::FirstParagraph);
|
||||
|
||||
QString contents;
|
||||
QMap<QString, QUrl> helpLinks = Core::HelpManager::instance()->linksForIdentifier(m_helpId);
|
||||
QMap<QString, QUrl> helpLinks = retrieveHelpLinks();
|
||||
if (helpLinks.isEmpty()) {
|
||||
// Maybe this is already an URL...
|
||||
QUrl url(m_helpId);
|
||||
@@ -134,3 +138,10 @@ QString HelpItem::extractContent(bool extended) const
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
QMap<QString, QUrl> HelpItem::retrieveHelpLinks() const
|
||||
{
|
||||
if (m_helpLinks.isEmpty())
|
||||
m_helpLinks = Core::HelpManager::instance()->linksForIdentifier(m_helpId);
|
||||
return m_helpLinks;
|
||||
}
|
||||
|
@@ -32,7 +32,9 @@
|
||||
|
||||
#include "texteditor_global.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
@@ -55,6 +57,8 @@ public:
|
||||
HelpItem();
|
||||
HelpItem(const QString &helpId, Category category);
|
||||
HelpItem(const QString &helpId, const QString &docMark, Category category);
|
||||
HelpItem(const QString &helpId, const QString &docMark, Category category,
|
||||
const QMap<QString, QUrl> &helpLinks);
|
||||
~HelpItem();
|
||||
|
||||
void setHelpId(const QString &id);
|
||||
@@ -70,10 +74,14 @@ public:
|
||||
|
||||
QString extractContent(bool extended) const;
|
||||
|
||||
private:
|
||||
QMap<QString, QUrl> retrieveHelpLinks() const;
|
||||
|
||||
private:
|
||||
QString m_helpId;
|
||||
QString m_docMark;
|
||||
Category m_category;
|
||||
mutable QMap<QString, QUrl> m_helpLinks; // cached help links
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
|
Reference in New Issue
Block a user