From 4d3ca81b0aeef6f6496f3e89451f5369ce5efa99 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 19 Feb 2010 12:26:32 +0100 Subject: QStringBuilder: reduce the size of the generated code A simple concatenation of 2 string does not benefit from the QStringBuilder trick, yet, this would produce more code with QT_USE_FAST_OPERATOR_PLUS This commit specialize the QStringBuilder with two QString so it produce the same code as without it. Reviewed-by: joao Reviewed-by: hjk --- src/corelib/tools/qstringbuilder.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index 74661c2..4ff1b36 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -117,6 +117,20 @@ public: }; +template <> +class QStringBuilder +{ + public: + QStringBuilder(const QString &a_, const QString &b_) : a(a_), b(b_) {} + + operator QString() const + { QString r(a); r += b; return r; } + QByteArray toLatin1() const { return QString(*this).toLatin1(); } + + const QString &a; + const QString &b; +}; + template <> struct QConcatenable : private QAbstractConcatenable { typedef char type; -- cgit v0.12 From 8302f412660410775887c6c524aa87fb67aebde1 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 19 Feb 2010 12:48:28 +0100 Subject: QStringBuilder: Do not resize if not required. This reduce a lot the binary size. And is also faster. It is not source compatible if customer have made their own QConcatenable. But this class is not documented, and it is easy to fix. Reviewed-by: Joao Reviewed-by: hjk --- src/corelib/tools/qstringbuilder.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index 4ff1b36..9fe3fd7 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -100,14 +100,18 @@ public: operator QString() const { - QString s(QConcatenable< QStringBuilder >::size(*this), - Qt::Uninitialized); + const uint size = QConcatenable< QStringBuilder >::size(*this); + QString s(size, Qt::Uninitialized); QChar *d = s.data(); + const QChar * const start = d; QConcatenable< QStringBuilder >::appendTo(*this, d); - // this resize is necessary since we allocate a bit too much - // when dealing with variable sized 8-bit encodings - s.resize(d - s.data()); + + if (!QConcatenable< QStringBuilder >::ExactSize && size != d - start) { + // this resize is necessary since we allocate a bit too much + // when dealing with variable sized 8-bit encodings + s.resize(d - start); + } return s; } QByteArray toLatin1() const { return QString(*this).toLatin1(); } @@ -116,7 +120,6 @@ public: const B &b; }; - template <> class QStringBuilder { @@ -134,6 +137,7 @@ class QStringBuilder template <> struct QConcatenable : private QAbstractConcatenable { typedef char type; + enum { ExactSize = true }; static int size(const char) { return 1; } static inline void appendTo(const char c, QChar *&out) { @@ -144,6 +148,7 @@ template <> struct QConcatenable : private QAbstractConcatenable template <> struct QConcatenable { typedef QLatin1Char type; + enum { ExactSize = true }; static int size(const QLatin1Char) { return 1; } static inline void appendTo(const QLatin1Char c, QChar *&out) { @@ -154,6 +159,7 @@ template <> struct QConcatenable template <> struct QConcatenable { typedef QChar type; + enum { ExactSize = true }; static int size(const QChar) { return 1; } static inline void appendTo(const QChar c, QChar *&out) { @@ -164,6 +170,7 @@ template <> struct QConcatenable template <> struct QConcatenable { typedef QCharRef type; + enum { ExactSize = true }; static int size(const QCharRef &) { return 1; } static inline void appendTo(const QCharRef &c, QChar *&out) { @@ -174,6 +181,7 @@ template <> struct QConcatenable template <> struct QConcatenable { typedef QLatin1String type; + enum { ExactSize = true }; static int size(const QLatin1String &a) { return qstrlen(a.latin1()); } static inline void appendTo(const QLatin1String &a, QChar *&out) { @@ -186,6 +194,7 @@ template <> struct QConcatenable template <> struct QConcatenable { typedef QLatin1Literal type; + enum { ExactSize = true }; static int size(const QLatin1Literal &a) { return a.size(); } static inline void appendTo(const QLatin1Literal &a, QChar *&out) { @@ -197,6 +206,7 @@ template <> struct QConcatenable template <> struct QConcatenable { typedef QString type; + enum { ExactSize = true }; static int size(const QString &a) { return a.size(); } static inline void appendTo(const QString &a, QChar *&out) { @@ -209,6 +219,7 @@ template <> struct QConcatenable template <> struct QConcatenable { typedef QStringRef type; + enum { ExactSize = true }; static int size(const QStringRef &a) { return a.size(); } static inline void appendTo(QStringRef a, QChar *&out) { @@ -222,6 +233,7 @@ template <> struct QConcatenable template struct QConcatenable : private QAbstractConcatenable { typedef char type[N]; + enum { ExactSize = false }; static int size(const char[N]) { return N - 1; @@ -235,6 +247,7 @@ template struct QConcatenable : private QAbstractConcatenable template struct QConcatenable : private QAbstractConcatenable { typedef const char type[N]; + enum { ExactSize = false }; static int size(const char[N]) { return N - 1; } static inline void appendTo(const char a[N], QChar *&out) { @@ -245,6 +258,7 @@ template struct QConcatenable : private QAbstractConcaten template <> struct QConcatenable : private QAbstractConcatenable { typedef char const *type; + enum { ExactSize = false }; static int size(const char *a) { return qstrlen(a); } static inline void appendTo(const char *a, QChar *&out) { @@ -255,6 +269,7 @@ template <> struct QConcatenable : private QAbstractConcatenable template <> struct QConcatenable : private QAbstractConcatenable { typedef QByteArray type; + enum { ExactSize = false }; static int size(const QByteArray &ba) { return qstrnlen(ba.constData(), ba.size()); } static inline void appendTo(const QByteArray &ba, QChar *&out) { @@ -267,6 +282,7 @@ template struct QConcatenable< QStringBuilder > { typedef QStringBuilder type; + enum { ExactSize = QConcatenable::ExactSize && QConcatenable::ExactSize }; static int size(const type &p) { return QConcatenable::size(p.a) + QConcatenable::size(p.b); -- cgit v0.12 From 5d3eb7a1062744afad06882e9a8f59c84fd4e8b7 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 18 Feb 2010 20:52:45 +0100 Subject: Compile with QT_USE_FAST_OPERATOR_PLUS Reviewed-by: Joao --- src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp | 4 ++-- src/corelib/io/qurl.cpp | 2 +- src/qt3support/text/q3textedit.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp index 7a1bfd5..5fbc876 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp @@ -179,7 +179,7 @@ void InspectorClientQt::populateSetting(const String& key, InspectorController:: return; } - QString settingKey(settingStoragePrefix + key); + QString settingKey(settingStoragePrefix + QString(key)); QString storedValueType = qsettings.value(settingKey + settingStorageTypeSuffix).toString(); QVariant storedValue = qsettings.value(settingKey); storedValue.convert(QVariant::nameToType(storedValueType.toAscii().data())); @@ -196,7 +196,7 @@ void InspectorClientQt::storeSetting(const String& key, const InspectorControlle } QVariant valueToStore = settingToVariant(setting); - QString settingKey(settingStoragePrefix + key); + QString settingKey(settingStoragePrefix + QString(key)); qsettings.setValue(settingKey, valueToStore); qsettings.setValue(settingKey + settingStorageTypeSuffix, QVariant::typeToName(valueToStore.type())); } diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 076cc33..0290fb8 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -6348,7 +6348,7 @@ QUrl QUrl::fromUserInput(const QString &userInput) return QUrl::fromLocalFile(trimmedString); QUrl url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode); - QUrl urlPrepended = QUrl::fromEncoded((QLatin1String("http://") + trimmedString).toUtf8(), QUrl::TolerantMode); + QUrl urlPrepended = QUrl::fromEncoded("http://" + trimmedString.toUtf8(), QUrl::TolerantMode); // Check the most common case of a valid url with scheme and host // We check if the port would be valid by adding the scheme to handle the case host:port diff --git a/src/qt3support/text/q3textedit.cpp b/src/qt3support/text/q3textedit.cpp index 7f51bea..d4f75ed 100644 --- a/src/qt3support/text/q3textedit.cpp +++ b/src/qt3support/text/q3textedit.cpp @@ -6238,7 +6238,7 @@ void Q3TextEdit::optimParseTags(QString * line, int lineNo, int indexOffset) } else { tmp = tagStack.isEmpty() ? 0 : tagStack.pop(); if (!tmp) { - if (((QLatin1Char('/') + cur->tag) == tag->tag) || + if ((QString(QLatin1Char('/') + cur->tag) == tag->tag) || (tag->tag == QLatin1String("/font") && cur->tag.left(4) == QLatin1String("font"))) { // set up the left and parent of this tag tag->leftTag = cur; -- cgit v0.12 From 1f0e2e9825453fc0d8efa91b21afa8e8a9b4951f Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 19 Feb 2010 13:39:56 +0100 Subject: Enable QT_USE_FAST_CONCATENATION by default for compiling Qt But disable it with GCC 4.0 as it is known to cause problems due to a compiler bug Reviewed-by: Joao Reviewed-by: hjk --- src/corelib/tools/qstring.h | 10 ++++++++++ src/qbase.pri | 1 + 2 files changed, 11 insertions(+) diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 8de3c7d..a59c0bd 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -73,6 +73,16 @@ typedef std::basic_string QStdWString; #error qstring.h must be included before any header file that defines truncate #endif +#if defined(Q_CC_GNU) && (__GNUC__ == 4 && __GNUC_MINOR__ == 0) +//There is a bug in GCC 4.0 that tries to instantiate template of annonymous enum +# ifdef QT_USE_FAST_OPERATOR_PLUS +# undef QT_USE_FAST_OPERATOR_PLUS +# endif +# ifdef QT_USE_FAST_CONCATENATION +# undef QT_USE_FAST_CONCATENATION +# endif +#endif + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE diff --git a/src/qbase.pri b/src/qbase.pri index ef5d9e5..835ed0e 100644 --- a/src/qbase.pri +++ b/src/qbase.pri @@ -157,6 +157,7 @@ contains(QT_PRODUCT, OpenSource.*):DEFINES *= QT_OPENSOURCE DEFINES *= QT_NO_CAST_TO_ASCII QT_ASCII_CAST_WARNINGS contains(QT_CONFIG, qt3support):DEFINES *= QT3_SUPPORT DEFINES *= QT_MOC_COMPAT #we don't need warnings from calling moc code in our generated code +DEFINES *= QT_USE_FAST_OPERATOR_PLUS QT_USE_FAST_CONCATENATION TARGET = $$qtLibraryTarget($$TARGET$$QT_LIBINFIX) #do this towards the end -- cgit v0.12 From f922243bbbab238fa63b220eaf74a5f1b429758c Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sun, 21 Feb 2010 19:52:54 +0100 Subject: Compilation on symbian --- src/corelib/tools/qlocale_symbian.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qlocale_symbian.cpp b/src/corelib/tools/qlocale_symbian.cpp index b1a7caa..58e3ba8 100644 --- a/src/corelib/tools/qlocale_symbian.cpp +++ b/src/corelib/tools/qlocale_symbian.cpp @@ -841,7 +841,7 @@ QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const return symbianTimeFormat(); case DateTimeFormatLong: case DateTimeFormatShort: - return symbianDateFormat( (type == DateTimeFormatShort) ) + QLatin1Char(' ') + symbianTimeFormat(); + return QString(symbianDateFormat( (type == DateTimeFormatShort) ) + QLatin1Char(' ') + symbianTimeFormat()); case DateToStringShort: case DateToStringLong: return symbianDateToString(in.toDate(), (type == DateToStringShort) ); @@ -851,8 +851,8 @@ QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const case DateTimeToStringShort: case DateTimeToStringLong: { const QDateTime dt = in.toDateTime(); - return symbianDateToString(dt.date(), (type == DateTimeToStringShort) ) - + QLatin1Char(' ') + symbianTimeToString(dt.time()); + return QString(symbianDateToString(dt.date(), (type == DateTimeToStringShort) ) + + QLatin1Char(' ') + symbianTimeToString(dt.time())); } case MeasurementSystem: return static_cast(symbianMeasurementSystem()); -- cgit v0.12 From f25f7a2a19ba4c21b7a5d9fee02a9ae71c9f60ef Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 22 Feb 2010 09:50:22 +0100 Subject: Copy useBackendOptimization setting when QStaticText is detached When the QStaticText is detached, we would previously reset the value of useBackendOptimizations rather than copy it into the new data. Reviewed-by: Gunnar --- src/gui/text/qstatictext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 623ee54..9313e65 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -356,7 +356,7 @@ QStaticTextPrivate::QStaticTextPrivate() QStaticTextPrivate::QStaticTextPrivate(const QStaticTextPrivate &other) : text(other.text), font(other.font), maximumSize(other.maximumSize), matrix(other.matrix), items(0), itemCount(0), glyphPool(0), positionPool(0), needsClipRect(false), - useBackendOptimizations(false), textFormat(other.textFormat) + useBackendOptimizations(other.useBackendOptimizations), textFormat(other.textFormat) { ref = 1; } -- cgit v0.12 From 1ecfec9950fb66378035f92be8c8b13b1b891872 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 22 Feb 2010 09:21:49 +0100 Subject: Fix compilation on Windows For some reason, the MSVC compiler choose the operator+(const QString &, const QString &) instead of operator+(const WebCore::String &, const WebCore::String &) resulting in errors when QT_USE_FAST_OPERATOR_PLUS is used Reviewed-by: Jocelyn Turcotte --- src/3rdparty/webkit/WebCore/dom/XMLTokenizerQt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/3rdparty/webkit/WebCore/dom/XMLTokenizerQt.cpp b/src/3rdparty/webkit/WebCore/dom/XMLTokenizerQt.cpp index 79fc51e..5c87fe6 100644 --- a/src/3rdparty/webkit/WebCore/dom/XMLTokenizerQt.cpp +++ b/src/3rdparty/webkit/WebCore/dom/XMLTokenizerQt.cpp @@ -368,7 +368,7 @@ static inline void handleElementNamespaces(Element* newElement, const QXmlStream for (int i = 0; i < ns.count(); ++i) { const QXmlStreamNamespaceDeclaration &decl = ns[i]; String namespaceURI = decl.namespaceUri(); - String namespaceQName = decl.prefix().isEmpty() ? String("xmlns") : String("xmlns:") + decl.prefix(); + String namespaceQName = decl.prefix().isEmpty() ? String("xmlns") : String("xmlns:") + String(decl.prefix()); newElement->setAttributeNS("http://www.w3.org/2000/xmlns/", namespaceQName, namespaceURI, ec); if (ec) // exception setting attributes return; -- cgit v0.12 From 10bec2ab7be43f4a8507901fc9eeecf0b33af5a1 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 22 Feb 2010 10:38:06 +0100 Subject: Fix compilation With the QT_USE_OPERATOR_PLUS, we need to cast before converting to QVariant --- tools/assistant/lib/qhelpdbreader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/assistant/lib/qhelpdbreader.cpp b/tools/assistant/lib/qhelpdbreader.cpp index 6dd949a..5c0f595 100644 --- a/tools/assistant/lib/qhelpdbreader.cpp +++ b/tools/assistant/lib/qhelpdbreader.cpp @@ -205,7 +205,7 @@ QByteArray QHelpDBReader::fileData(const QString &virtualFolder, "NamespaceTable d WHERE a.Id=b.FileId AND (b.Name=? OR b.Name=?) AND b.FolderId=c.Id " "AND c.Name=? AND c.NamespaceId=d.Id AND d.Name=?")); m_query->bindValue(0, filePath); - m_query->bindValue(1, QLatin1String("./") + filePath); + m_query->bindValue(1, QString(QLatin1String("./") + filePath)); m_query->bindValue(2, virtualFolder); m_query->bindValue(3, m_namespace); m_query->exec(); -- cgit v0.12 From b9db89f7d299305769e207088a00345dbe82cf1d Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 22 Feb 2010 11:32:39 +0100 Subject: Fix build on Mac OS X Reviewed-by: Olivier --- src/corelib/global/qlibraryinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index a9ea44a..d5041c9 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -439,7 +439,7 @@ QLibraryInfo::location(LibraryLocation loc) QCFType urlRef = CFBundleCopyBundleURL(bundleRef); if (urlRef) { QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle); - return QDir::cleanPath(path + QLatin1String("/Contents/") + ret); + return QDir::cleanPath(QString(path) + QLatin1String("/Contents/") + ret); } } #endif -- cgit v0.12 From 460394f8f225cc60e5dc1ad9804a6c8dd078fc05 Mon Sep 17 00:00:00 2001 From: aavit Date: Mon, 22 Feb 2010 12:30:55 +0100 Subject: Compilation fix for AIX --- src/3rdparty/libpng/png.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/3rdparty/libpng/png.h b/src/3rdparty/libpng/png.h index 14e3416..5ea2b0d 100644 --- a/src/3rdparty/libpng/png.h +++ b/src/3rdparty/libpng/png.h @@ -386,7 +386,7 @@ #include "zlib.h" #endif -#ifdef AIX +#ifdef _AIX #define jmpbuf __jmpbuf #endif -- cgit v0.12