> -----Original Message-----
> From: Martin Sebor [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, October 11, 2006 8:10 PM
> To: [email protected]
> Subject: Re: [PATCH] bitset.cc (STDCXX-297)
>
[...]
> We could deal with it by having
> two code paths, a faster one for power-of-2 CHAR_BIT values
> and a slower one for the rare cases when it isn't (guarded by
> suitable #if's).
New patch is attached.
Farid.
Index: bitset.cc
===================================================================
--- bitset.cc (revision 465232)
+++ bitset.cc (working copy)
@@ -22,6 +22,29 @@
_RWSTD_NAMESPACE (__rw) {
+#if 8 == _RWSTD_CHAR_BIT
+# define _RWSTD_LOG2_CHAR_BITS 3
+#elif 16 == _RWSTD_CHAR_BIT
+# define _RWSTD_LOG2_CHAR_BITS 4
+#elif 32 == _RWSTD_CHAR_BIT
+# define _RWSTD_LOG2_CHAR_BITS 5
+#elif 64 == _RWSTD_CHAR_BIT
+# define _RWSTD_LOG2_CHAR_BITS 6
+#endif
+
+#if 1 == _RWSTD_LONG_SIZE
+# define _RWSTD_LOG2_LONG_SIZE 0
+#elif 2 == _RWSTD_LONG_SIZE
+# define _RWSTD_LOG2_LONG_SIZE 1
+#elif 4 == _RWSTD_LONG_SIZE
+# define _RWSTD_LOG2_LONG_SIZE 2
+#elif 8 == _RWSTD_LONG_SIZE
+# define _RWSTD_LOG2_LONG_SIZE 3
+#elif 16 == _RWSTD_LONG_SIZE
+# define _RWSTD_LOG2_LONG_SIZE 4
+#endif
+
+
_EXPORT
template <class _CharT, class _Traits>
void __rw_bitset (unsigned long *__bits, _RWSTD_SIZE_T __maxbits,
@@ -51,9 +74,20 @@
__str += __pos;
// compute the number of bytes occupied by `bits'
+#if defined (_RWSTD_LOG2_CHAR_BITS) && defined (_RWSTD_LOG2_LONG_SIZE)
+
const _RWSTD_SIZE_T __nbytes =
- (__maxbits + sizeof *__bits * _RWSTD_CHAR_BIT - 1) / _RWSTD_CHAR_BIT;
+ ((__maxbits >> (_RWSTD_LOG2_CHAR_BITS + _RWSTD_LOG2_LONG_SIZE)) +
+ (0 != (__maxbits & (__wordbits - 1)))) << _RWSTD_LOG2_LONG_SIZE;
+#else // #if !defined (_RWSTD_LOG2_CHAR_BITS) || !defined
(_RWSTD_LOG2_LONG_SIZE)
+
+ const _RWSTD_SIZE_T __nbytes =
+ (__maxbits / __wordbits + (0 != __maxbits % __wordbits))
+ * sizeof (*__bits);
+
+#endif // _RWSTD_LOG2_CHAR_BITS && _RWSTD_LOG2_LONG_SIZE
+
_RWSTD_MEMSET (__bits, 0, __nbytes);
// set all bits but also check any extra characters as required
@@ -74,7 +108,10 @@
}
}
+#undef _RWSTD_LOG2_CHAR_BITS
+#undef _RWSTD_LOG2_ULONG_SIZE
+
_EXPORT
template <_RWSTD_SIZE_T _Size, class _CharT, class _Traits>
_STD::basic_istream<_CharT, _Traits>&