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 <qt_sanity_bot@ovi.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
parent
4cd9d267e7
commit
5639423ea7
@ -601,12 +601,19 @@ bool QChar::isLetterOrNumber() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
\fn bool QChar::isDigit() const
|
||||||
|
|
||||||
Returns true if the character is a decimal digit
|
Returns true if the character is a decimal digit
|
||||||
(Number_DecimalDigit); otherwise returns false.
|
(Number_DecimalDigit); otherwise returns false.
|
||||||
*/
|
*/
|
||||||
bool QChar::isDigit() const
|
|
||||||
|
/*!
|
||||||
|
\internal
|
||||||
|
\overload
|
||||||
|
*/
|
||||||
|
bool QChar::isDigit(ushort ucs2)
|
||||||
{
|
{
|
||||||
return (qGetProp(ucs)->category == Number_DecimalDigit);
|
return (qGetProp(ucs2)->category == Number_DecimalDigit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -237,7 +237,8 @@ public:
|
|||||||
bool isLetter() const;
|
bool isLetter() const;
|
||||||
bool isNumber() const;
|
bool isNumber() const;
|
||||||
bool isLetterOrNumber() const;
|
bool isLetterOrNumber() const;
|
||||||
bool isDigit() const;
|
inline bool isDigit() const
|
||||||
|
{ return (ucs <= '9' && ucs >= '0') || (ucs > 127 && isDigit(ucs)); }
|
||||||
bool isSymbol() const;
|
bool isSymbol() const;
|
||||||
inline bool isLower() const {
|
inline bool isLower() const {
|
||||||
return (ucs >= 'a' && ucs <= 'z')
|
return (ucs >= 'a' && ucs <= 'z')
|
||||||
@ -315,6 +316,8 @@ public:
|
|||||||
static QString QT_FASTCALL decomposition(uint ucs4);
|
static QString QT_FASTCALL decomposition(uint ucs4);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static bool QT_FASTCALL isDigit(ushort ucs2);
|
||||||
|
|
||||||
#ifdef QT_NO_CAST_FROM_ASCII
|
#ifdef QT_NO_CAST_FROM_ASCII
|
||||||
QChar(char c);
|
QChar(char c);
|
||||||
QChar(uchar c);
|
QChar(uchar c);
|
||||||
|
@ -73,6 +73,8 @@ private slots:
|
|||||||
void toLower();
|
void toLower();
|
||||||
void toTitle();
|
void toTitle();
|
||||||
void toCaseFolded();
|
void toCaseFolded();
|
||||||
|
void isDigit_data();
|
||||||
|
void isDigit();
|
||||||
void isPrint();
|
void isPrint();
|
||||||
void isUpper();
|
void isUpper();
|
||||||
void isLower();
|
void isLower();
|
||||||
@ -223,6 +225,25 @@ void tst_QChar::toCaseFolded()
|
|||||||
QVERIFY(QChar::toCaseFolded((ushort)0xb5) == 0x3bc);
|
QVERIFY(QChar::toCaseFolded((ushort)0xb5) == 0x3bc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QChar::isDigit_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<ushort>("ucs");
|
||||||
|
QTest::addColumn<bool>("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()
|
void tst_QChar::isPrint()
|
||||||
{
|
{
|
||||||
QVERIFY(QChar('A').isPrint());
|
QVERIFY(QChar('A').isPrint());
|
||||||
|
Loading…
Reference in New Issue
Block a user