From 5639423ea7322d5880d68c61c480a3a084ac4f8b Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 14 Sep 2011 12:53:20 +0200 Subject: Boost performance of QChar::isDigit Make it inline; add fast checks for ascii digits; add fallback function that uses the fastcall calling convention. On ia32, this change makes isDigit ~370x faster for ascii digit characters, ~250x faster for non-digit ascii characters, and ~1.5x 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: I718fadecda3f591d6f4c22374d8e476f4724fd83 Reviewed-on: http://codereview.qt-project.org/4902 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') diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp index 02807f38b3..5a2a4834db 100644 --- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp @@ -73,6 +73,8 @@ private slots: void toLower(); void toTitle(); void toCaseFolded(); + void isDigit_data(); + void isDigit(); void isPrint(); void isUpper(); void isLower(); @@ -223,6 +225,25 @@ void tst_QChar::toCaseFolded() QVERIFY(QChar::toCaseFolded((ushort)0xb5) == 0x3bc); } +void tst_QChar::isDigit_data() +{ + QTest::addColumn("ucs"); + QTest::addColumn("expected"); + + for (ushort ucs = 0; ucs < 256; ++ucs) { + bool isDigit = (ucs <= '9' && ucs >= '0'); + QString tag = QString::fromLatin1("0x%0").arg(QString::number(ucs, 16)); + QTest::newRow(tag.toLatin1()) << ucs << isDigit; + } +} + +void tst_QChar::isDigit() +{ + QFETCH(ushort, ucs); + QFETCH(bool, expected); + QCOMPARE(QChar(ucs).isDigit(), expected); +} + void tst_QChar::isPrint() { QVERIFY(QChar('A').isPrint()); -- cgit v1.2.3