summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2011-09-14 12:15:07 +0200
committerQt by Nokia <qt-info@nokia.com>2011-09-15 20:39:28 +0200
commit4cd9d267e727b0b146f0f2d5b41cf62c97145fb4 (patch)
tree272f0d0143ad2470c9a875fee62cd3ecdf553f6a /src
parent6e557155810505525ec976cf7b9421e5c8970b55 (diff)
Boost performance of QChar::is{Upper,Lower}
Calling QChar::category() is slow; do some fast checks to detect ascii characters before falling back to the generic handling. On ia32, this change makes isUpper ~260x faster for uppercase ascii characters, and ~180x faster for non-uppercase ascii characters. Similar numbers for isLower. Even with the additional checks, these versions are slightly faster than before for non-ascii characters as well, since we now call the static fastcall category(ushort) function, which is faster than the category() member function (which uses the stack to pass the unicode value). Change-Id: I6ae0df466bb4835ca0d5319fd6018862c849313b Reviewed-on: http://codereview.qt-project.org/4901 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qchar.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h
index af50f6dde7..3efa5e511d 100644
--- a/src/corelib/tools/qchar.h
+++ b/src/corelib/tools/qchar.h
@@ -239,8 +239,14 @@ public:
bool isLetterOrNumber() const;
bool isDigit() const;
bool isSymbol() const;
- inline bool isLower() const { return category() == Letter_Lowercase; }
- inline bool isUpper() const { return category() == Letter_Uppercase; }
+ inline bool isLower() const {
+ return (ucs >= 'a' && ucs <= 'z')
+ || (ucs > 127 && category(ucs) == Letter_Lowercase);
+ }
+ inline bool isUpper() const {
+ return (ucs <= 'Z' && ucs >= 'A')
+ || (ucs > 127 && category(ucs) == Letter_Uppercase);
+ }
inline bool isTitleCase() const { return category() == Letter_Titlecase; }
inline bool isHighSurrogate() const {