From c250a0ec3a196247dde372cde3757913226386b0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 29 Jul 2014 14:35:11 -0700 Subject: Unify and optimize QByteArray::to{Upper,Lower} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do a check first if we need to transform before doing the transform. This means we won't detach when transforming data that is already correct. And instead of using QChar, use our own hand-rolled table. In a proper LTO build, the QChar calls would be resolved to a lookup of the Unicode data, but not many people do LTO builds, Therefore, this means a great speed-up is achieved by simply avoiding the function call. The extra gain in performance comes from the simpler translation table instead of the more complex full-Unicode data. Also as a consequence, this changes the handling of two characters in Latin 1: 'ß' should be uppercased to "SS" but we won't do it, and 'ÿ' can't be uppercased in Latin 1 ('Ÿ' is outside the range). Benchmarking is included. Comparing the Qt 5.4 algorithm to the new code is almost 20x faster. Other alternatives are included in the benchmark and are all faster than the current code, though slower than the new one. While all of them could compress the tables to be smaller or shared between uppercasing and lowercasing, they would also expand to more code (though probably less than the extra bytes required in the full translation table). In the trade-off, I decided to go with simplicity and most efficient code. Change-Id: I002d98318d236de0d27ffbea39d662cbed359985 Reviewed-by: Marc Mutz --- tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp') diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp index 52e1850c87..8670e4b3ef 100644 --- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp @@ -2022,6 +2022,8 @@ void tst_QByteArray::toUpperLower() QFETCH(QByteArray, input); QFETCH(QByteArray, upper); QFETCH(QByteArray, lower); + QCOMPARE(lower.toLower(), lower); + QCOMPARE(upper.toUpper(), upper); QCOMPARE(input.toUpper(), upper); QCOMPARE(input.toLower(), lower); } -- cgit v1.2.3