This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Tweak _generic_/ctype_members.cc (do_is(mask, wchar_t) for iswspace
- From: Danny Smith <dannysmith at clear dot net dot nz>
- To: GCC-patches <gcc-patches at gcc dot gnu dot org>, libstdc++ at gcc dot gnu dot org
- Date: Tue, 26 Jun 2007 20:41:06 +1200
- Subject: Tweak _generic_/ctype_members.cc (do_is(mask, wchar_t) for iswspace
Hello, 2 years ago, Paolo did this tweak for GNU/ctype_members.cc
2005-07-18 Paolo Carlini <pcarlini@suse.de>
* config/locale/gnu/ctype_members.cc (do_is(mask, wchar_t)):
Speed-up for the common case of mask == ctype_base::space;
otherwise, exit the loop earlier if the mask is one of the
elementary ones.
Is it it worthwhile to allow same "common case" tweak for generic?
It works on cygwin and mingw32. But, to be honest, I have not really
tried to measure a performance effect on those two targets.
2007-06-25 Danny Smith <dannysmith@users.sourceforege.net>
* config/locale/gnu/ctype_members.cc (do_is(mask, wchar_t))
[_GLIBCXX_CTYPE_SPACE_BIT]: Speed-up for the common case of
mask == ctype_base::space,
* config/os/mingw32/ctype_base.h: (_GLIBCXX_CTYPE_SPACE_BIT):
Define
* config/os/newlib/ctype_base.h (_GLIBCXX_CTYPE_SPACE_BIT):
Define.
Index: config/locale/generic/ctype_members.cc
===================================================================
--- config/locale/generic/ctype_members.cc (revision 126014)
+++ config/locale/generic/ctype_members.cc (working copy)
@@ -136,17 +136,31 @@
(mask __m, char_type __c) const
{
bool __ret = false;
- // Generically, 15 (instead of 10) since we don't know the
numerical
- // encoding of the various categories in /usr/include/ctype.h.
- const size_t __bitmasksize = 15;
- for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
- if (__m & _M_bit[__bitcur]
- && iswctype(__c, _M_wmask[__bitcur]))
- {
- __ret = true;
- break;
- }
- return __ret;
+
+#ifdef _GLIBCXX_CTYPE_SPACE_BIT
+ // The case of __m == ctype_base::space is particularly important,
+ // due to its use in many istream functions. Therefore we deal
with
+ // it first, exploiting the knowledge that on some systems we know
+ // which bit is the mask corresponding to ctype_base::space.
+ // NB: an encoding change would not affect correctness!
+ if (__m == _M_bit[_GLIBCXX_CTYPE_SPACE_BIT])
+ __ret = iswctype(__c, _M_wmask[_GLIBCXX_CTYPE_SPACE_BIT]);
+ else
+#endif
+ {
+ // Generically, 15 (instead of 10) since we don't know the
+ // numerical encoding of the various categories in
+ // /usr/include/ctype.h.
+ const size_t __bitmasksize = 15;
+ for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
+ if (__m & _M_bit[__bitcur]
+ && iswctype(__c, _M_wmask[__bitcur]))
+ {
+ __ret = true;
+ break;
+ }
+ }
+ return __ret;
}
const wchar_t*
Index: config/os/newlib/ctype_base.h
===================================================================
--- config/os/newlib/ctype_base.h (revision 126014)
+++ config/os/newlib/ctype_base.h (working copy)
@@ -51,7 +51,7 @@
static const mask alpha = _U | _L;
static const mask digit = _N;
static const mask xdigit = _X | _N;
- static const mask space = _S;
+ static const mask space = _S; // 1 << 3
static const mask print = _P | _U | _L | _N | _B;
static const mask graph = _P | _U | _L | _N;
static const mask cntrl = _C;
@@ -59,4 +59,7 @@
static const mask alnum = _U | _L | _N;
};
+#define _GLIBCXX_CTYPE_SPACE_BIT 3
+
_GLIBCXX_END_NAMESPACE
Index: config/os/mingw32/ctype_base.h
===================================================================
--- config/os/mingw32/ctype_base.h (revision 126014)
+++ config/os/mingw32/ctype_base.h (working copy)
@@ -49,7 +49,7 @@
static const mask alpha = _ALPHA;
static const mask digit = _DIGIT;
static const mask xdigit = _HEX;
- static const mask space = _SPACE;
+ static const mask space = _SPACE; // 1 << 3
static const mask print = (_BLANK | _PUNCT| _ALPHA | _DIGIT);
static const mask graph = (_PUNCT | _ALPHA | _DIGIT);
static const mask cntrl = _CONTROL;
@@ -57,4 +57,7 @@
static const mask alnum = (_ALPHA | _DIGIT);
};
+#define _GLIBCXX_CTYPE_SPACE_BIT 3
+
_GLIBCXX_END_NAMESPACE
+