From 08d1ca10537b2005fa0ff93534272e277b3ae821 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 14 Sep 2011 13:50:36 +0200 Subject: Boost performance of QChar::isLetterOrNumber Make it inline; add fast checks for ascii letters and digits; add fallback function that uses the fastcall calling convention. On ia32, this change makes isLetterOrNumber ~120x faster for ascii letters and digits, ~150x faster for non-letter/digit 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: Ia4e13692f4dd79f6aa0b96da29449e0487971b0e Reviewed-on: http://codereview.qt-project.org/4904 Reviewed-by: Qt Sanity Bot Reviewed-by: Lars Knoll --- src/corelib/tools/qchar.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/corelib/tools/qchar.h') diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h index fc5a9b051d..36e185ebce 100644 --- a/src/corelib/tools/qchar.h +++ b/src/corelib/tools/qchar.h @@ -240,7 +240,13 @@ public: || (ucs > 127 && isLetter(ucs)); } bool isNumber() const; - bool isLetterOrNumber() const; + inline bool isLetterOrNumber() const + { + return (ucs >= 'a' && ucs <= 'z') + || (ucs <= 'Z' && ucs >= 'A') + || (ucs <= '9' && ucs >= '0') + || (ucs > 127 && isLetterOrNumber(ucs)); + } inline bool isDigit() const { return (ucs <= '9' && ucs >= '0') || (ucs > 127 && isDigit(ucs)); } bool isSymbol() const; @@ -322,6 +328,7 @@ public: private: static bool QT_FASTCALL isDigit(ushort ucs2); static bool QT_FASTCALL isLetter(ushort ucs2); + static bool QT_FASTCALL isLetterOrNumber(ushort ucs2); #ifdef QT_NO_CAST_FROM_ASCII QChar(char c); -- cgit v1.2.3