From 8e67ef47942f7d7034ccf2166411d2bf1668c1e2 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 14 Sep 2011 14:11:17 +0200 Subject: Boost performance of QChar::isSpace Make it inline; add fast checks for typical spaces; add fallback function that uses the fastcall calling convention. On ia32, this change makes isSpace ~340x faster for ascii spaces, ~170x faster for non-space ascii characters, and ~1.3x faster for non-ascii characters. Note that this change is NOT binary compatible. Also add an autotest with expected results from before the optimization, to ensure that the behavior is the same. Change-Id: I9438d0ad3c9ba2e80560c4bee7eed05115265798 Reviewed-on: http://codereview.qt-project.org/4905 Reviewed-by: Qt Sanity Bot Reviewed-by: Lars Knoll --- tests/auto/corelib/tools/qchar/tst_qchar.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/auto/corelib/tools') diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp index f16d32a4f9..195abcd578 100644 --- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp @@ -82,6 +82,8 @@ private slots: void isPrint(); void isUpper(); void isLower(); + void isSpace_data(); + void isSpace(); void isTitle(); void category(); void direction(); @@ -335,6 +337,25 @@ void tst_QChar::isLower() } } +void tst_QChar::isSpace_data() +{ + QTest::addColumn("ucs"); + QTest::addColumn("expected"); + + for (ushort ucs = 0; ucs < 256; ++ucs) { + bool isSpace = (ucs <= 0x0D && ucs >= 0x09) || ucs == 0x20 || ucs == 0xA0; + QString tag = QString::fromLatin1("0x%0").arg(QString::number(ucs, 16)); + QTest::newRow(tag.toLatin1()) << ucs << isSpace; + } +} + +void tst_QChar::isSpace() +{ + QFETCH(ushort, ucs); + QFETCH(bool, expected); + QCOMPARE(QChar(ucs).isSpace(), expected); +} + void tst_QChar::isTitle() { for (uint codepoint = 0; codepoint <= UNICODE_LAST_CODEPOINT; ++codepoint) { -- cgit v1.2.3