summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/tools.pri
diff options
context:
space:
mode:
authorhjk <qtc-committer@nokia.com>2009-05-28 11:18:00 (GMT)
committerhjk <qtc-committer@nokia.com>2009-05-28 11:38:55 (GMT)
commit3331605529d2d81145259fd56d03bb59c480cac5 (patch)
tree4c716283b4fa714479a4f923019eaebd948de88a /src/corelib/tools/tools.pri
parent389ca4b5931efbf2bcac050ec80ec7971b61c857 (diff)
downloadQt-3331605529d2d81145259fd56d03bb59c480cac5.zip
Qt-3331605529d2d81145259fd56d03bb59c480cac5.tar.gz
Qt-3331605529d2d81145259fd56d03bb59c480cac5.tar.bz2
Introduce a new class QStringBuilder to speed up the creation of
QString objects from smaller chunks. The QStringBuilder class: QStringBuilder uses expression templates (using the '%' operator) to postpone any actual concatenation until it is assigned to an actual QString. At that time it knows the exact sizes of all chunks, can compute the required space, allocates once a QString of appriopriate size and then copies over the chunk data one-by-one. In addition, QLatin1Literal is a drop-in replacement for QLatin1String (which we can't change for compatibility reasons) that knows its size, therefore saving a few cycles when computing the size of the resulting string. Some further saved cycles stem from inlining and reduced reference counting logic (the QString created from a QStringBuilder has typically ref count equal to 1, while QString::append() needs an extra test) Minor changes to the existing QString class: - Introduce QString constructor to create an uninitialized QString of a given size. This particular constructor is used by QStringBuilder class. - Introduce a QT_USE_FAST_CONCATENATION macro to disable the existing overloads of operator+() and helps finding the places where they are used in code. - Introduce QT_USE_FAST_OPERATOR_PLUS. This also disables the existing overloads of operator+() and creates a new templated operator+() with identical implementation of operator%(). This allows code that is compilable QT_CAST_{TO,FROM}_ASCII to use QStringBuilder almost transparently. The only case that is not covered is creating objects like QUrl that are implicitly constructible from a QString from a QStringBuilder result. This needs to be converted explicitly to a QString first, e.g. by using QUrl url(QString(QLatin1String("http://") + hostName)); Reviewed-by: MariusSO
Diffstat (limited to 'src/corelib/tools/tools.pri')
-rw-r--r--src/corelib/tools/tools.pri2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri
index 90287cb..aea0c6c 100644
--- a/src/corelib/tools/tools.pri
+++ b/src/corelib/tools/tools.pri
@@ -32,6 +32,7 @@ HEADERS += \
tools/qsize.h \
tools/qstack.h \
tools/qstring.h \
+ tools/qstringbuilder.h \
tools/qstringlist.h \
tools/qstringmatcher.h \
tools/qtextboundaryfinder.h \
@@ -62,6 +63,7 @@ SOURCES += \
tools/qsharedpointer.cpp \
tools/qsize.cpp \
tools/qstring.cpp \
+ tools/qstringbuilder.cpp \
tools/qstringlist.cpp \
tools/qtextboundaryfinder.cpp \
tools/qtimeline.cpp \