summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/qstringbuilder/qstringbuilder.pro
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 /tests/benchmarks/qstringbuilder/qstringbuilder.pro
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 'tests/benchmarks/qstringbuilder/qstringbuilder.pro')
-rw-r--r--tests/benchmarks/qstringbuilder/qstringbuilder.pro12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/benchmarks/qstringbuilder/qstringbuilder.pro b/tests/benchmarks/qstringbuilder/qstringbuilder.pro
new file mode 100644
index 0000000..79171b4
--- /dev/null
+++ b/tests/benchmarks/qstringbuilder/qstringbuilder.pro
@@ -0,0 +1,12 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qstringbuilder
+
+QMAKE_CXXFLAGS += -g
+QMAKE_CFLAGS += -g
+
+QT -= gui
+
+CONFIG += release
+
+SOURCES += main.cpp