uic: use a real ordered set

... instead of QMap<Key, bool>. Since Qt doesn't have such
a container, use std::set instead, which also simplifies
some code, in particular, because, unlike the Qt containers,
it does the right thing on attempted duplicate insertion:
nothing.

Saves 6.5KiB in text size (1.1% of total) on optimized
GCC 5.3 Linux AMD64 builds.

Change-Id: I9578a9a58c1c06abe58f22a5b6127d43c2f4be12
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Marc Mutz 2016-01-29 11:29:51 +01:00
parent efe6efe627
commit 446afc1045
2 changed files with 15 additions and 13 deletions

View File

@ -114,8 +114,9 @@ void WriteIncludes::acceptUI(DomUI *node)
TreeWalker::acceptUI(node); TreeWalker::acceptUI(node);
if (!m_uic->option().includeFile.isEmpty()) const auto includeFile = m_uic->option().includeFile;
m_globalIncludes.insert(m_uic->option().includeFile, true); if (!includeFile.isEmpty())
m_globalIncludes.insert(includeFile);
writeHeaders(m_globalIncludes, true); writeHeaders(m_globalIncludes, true);
writeHeaders(m_localIncludes, false); writeHeaders(m_localIncludes, false);
@ -272,10 +273,11 @@ void WriteIncludes::insertInclude(const QString &header, bool global)
fprintf(stderr, "%s %s %d\n", Q_FUNC_INFO, qPrintable(header), global); fprintf(stderr, "%s %s %d\n", Q_FUNC_INFO, qPrintable(header), global);
OrderedSet &includes = global ? m_globalIncludes : m_localIncludes; OrderedSet &includes = global ? m_globalIncludes : m_localIncludes;
if (includes.contains(header)) // Insert (if not already done).
const bool isNewHeader = includes.insert(header).second;
if (!isNewHeader)
return; return;
// Insert. Also remember base name for quick check of suspicious custom plugins // Also remember base name for quick check of suspicious custom plugins
includes.insert(header, false);
const QString lowerBaseName = QFileInfo(header).completeBaseName ().toLower(); const QString lowerBaseName = QFileInfo(header).completeBaseName ().toLower();
m_includeBaseNames.insert(lowerBaseName); m_includeBaseNames.insert(lowerBaseName);
} }
@ -286,13 +288,11 @@ void WriteIncludes::writeHeaders(const OrderedSet &headers, bool global)
const QChar closingQuote = global ? QLatin1Char('>') : QLatin1Char('"'); const QChar closingQuote = global ? QLatin1Char('>') : QLatin1Char('"');
// Check for the old headers 'qslider.h' and replace by 'QtGui/QSlider' // Check for the old headers 'qslider.h' and replace by 'QtGui/QSlider'
const OrderedSet::const_iterator cend = headers.constEnd(); for (const QString &header : headers) {
for (OrderedSet::const_iterator sit = headers.constBegin(); sit != cend; ++sit) { const QString value = m_oldHeaderToNewHeader.value(header, header);
const StringMap::const_iterator hit = m_oldHeaderToNewHeader.constFind(sit.key()); const auto trimmed = QStringRef(&value).trimmed();
const bool mapped = hit != m_oldHeaderToNewHeader.constEnd(); if (!trimmed.isEmpty())
const QString header = mapped ? hit.value() : sit.key(); m_output << "#include " << openingQuote << trimmed << closingQuote << QLatin1Char('\n');
if (!QStringRef(&header).trimmed().isEmpty())
m_output << "#include " << openingQuote << header << closingQuote << QLatin1Char('\n');
} }
} }

View File

@ -35,6 +35,8 @@
#include <qset.h> #include <qset.h>
#include <qstring.h> #include <qstring.h>
#include <set>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QTextStream; class QTextStream;
@ -72,7 +74,7 @@ private:
void add(const QString &className, bool determineHeader = true, const QString &header = QString(), bool global = false); void add(const QString &className, bool determineHeader = true, const QString &header = QString(), bool global = false);
private: private:
typedef QMap<QString, bool> OrderedSet; typedef std::set<QString> OrderedSet;
void insertIncludeForClass(const QString &className, QString header = QString(), bool global = false); void insertIncludeForClass(const QString &className, QString header = QString(), bool global = false);
void insertInclude(const QString &header, bool global); void insertInclude(const QString &header, bool global);
void writeHeaders(const OrderedSet &headers, bool global); void writeHeaders(const OrderedSet &headers, bool global);