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);
if (!m_uic->option().includeFile.isEmpty())
m_globalIncludes.insert(m_uic->option().includeFile, true);
const auto includeFile = m_uic->option().includeFile;
if (!includeFile.isEmpty())
m_globalIncludes.insert(includeFile);
writeHeaders(m_globalIncludes, true);
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);
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;
// Insert. Also remember base name for quick check of suspicious custom plugins
includes.insert(header, false);
// Also remember base name for quick check of suspicious custom plugins
const QString lowerBaseName = QFileInfo(header).completeBaseName ().toLower();
m_includeBaseNames.insert(lowerBaseName);
}
@ -286,13 +288,11 @@ void WriteIncludes::writeHeaders(const OrderedSet &headers, bool global)
const QChar closingQuote = global ? QLatin1Char('>') : QLatin1Char('"');
// Check for the old headers 'qslider.h' and replace by 'QtGui/QSlider'
const OrderedSet::const_iterator cend = headers.constEnd();
for (OrderedSet::const_iterator sit = headers.constBegin(); sit != cend; ++sit) {
const StringMap::const_iterator hit = m_oldHeaderToNewHeader.constFind(sit.key());
const bool mapped = hit != m_oldHeaderToNewHeader.constEnd();
const QString header = mapped ? hit.value() : sit.key();
if (!QStringRef(&header).trimmed().isEmpty())
m_output << "#include " << openingQuote << header << closingQuote << QLatin1Char('\n');
for (const QString &header : headers) {
const QString value = m_oldHeaderToNewHeader.value(header, header);
const auto trimmed = QStringRef(&value).trimmed();
if (!trimmed.isEmpty())
m_output << "#include " << openingQuote << trimmed << closingQuote << QLatin1Char('\n');
}
}

View File

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