From 446afc10451d5097d7bd20b1b8d20325c4d54fa5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 29 Jan 2016 11:29:51 +0100 Subject: uic: use a real ordered set ... instead of QMap. 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 --- src/tools/uic/cpp/cppwriteincludes.cpp | 24 ++++++++++++------------ src/tools/uic/cpp/cppwriteincludes.h | 4 +++- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src/tools') diff --git a/src/tools/uic/cpp/cppwriteincludes.cpp b/src/tools/uic/cpp/cppwriteincludes.cpp index a99d6adf07..dcbe400224 100644 --- a/src/tools/uic/cpp/cppwriteincludes.cpp +++ b/src/tools/uic/cpp/cppwriteincludes.cpp @@ -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'); } } diff --git a/src/tools/uic/cpp/cppwriteincludes.h b/src/tools/uic/cpp/cppwriteincludes.h index 397c6a26e1..7a6a499536 100644 --- a/src/tools/uic/cpp/cppwriteincludes.h +++ b/src/tools/uic/cpp/cppwriteincludes.h @@ -35,6 +35,8 @@ #include #include +#include + 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 OrderedSet; + typedef std::set 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); -- cgit v1.2.3