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 --- src/corelib/tools/qchar.cpp | 13 +++++++++---- src/corelib/tools/qchar.h | 6 +++++- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index 56773bd527..a60fac4a7b 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -511,18 +511,23 @@ bool QChar::isPrint() const } /*! + \fn bool QChar::isSpace() const + Returns true if the character is a separator character (Separator_* categories or certain code points from Other_Control category); otherwise returns false. */ -bool QChar::isSpace() const + +/*! + \internal + \overload +*/ +bool QChar::isSpace(ushort ucs2) { - if(ucs >= 9 && ucs <=13) - return true; const int test = FLAG(Separator_Space) | FLAG(Separator_Line) | FLAG(Separator_Paragraph); - return FLAG(qGetProp(ucs)->category) & test; + return FLAG(qGetProp(ucs2)->category) & test; } /*! diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h index 36e185ebce..b82addb4c5 100644 --- a/src/corelib/tools/qchar.h +++ b/src/corelib/tools/qchar.h @@ -232,7 +232,10 @@ public: inline bool isNull() const { return ucs == 0; } bool isPrint() const; bool isPunct() const; - bool isSpace() const; + inline bool isSpace() const { + return ucs == 0x20 || (ucs <= 0x0D && ucs >= 0x09) + || (ucs > 127 && isSpace(ucs)); + } bool isMark() const; inline bool isLetter() const { return (ucs >= 'a' && ucs <= 'z') @@ -329,6 +332,7 @@ private: static bool QT_FASTCALL isDigit(ushort ucs2); static bool QT_FASTCALL isLetter(ushort ucs2); static bool QT_FASTCALL isLetterOrNumber(ushort ucs2); + static bool QT_FASTCALL isSpace(ushort ucs2); #ifdef QT_NO_CAST_FROM_ASCII QChar(char c); -- cgit v1.2.3