You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Farid Zaripov <Fa...@kyiv.vdiweb.com> on 2006/10/06 14:46:13 UTC
[PATCH] bitset.cc (STDCXX-297)
Below is a small patch to resolve issue STDCXX-297:
Index: bitset.cc
===================================================================
--- bitset.cc (revision 453570)
+++ bitset.cc (working copy)
@@ -52,7 +52,7 @@
// compute the number of bytes occupied by `bits'
const _RWSTD_SIZE_T __nbytes =
- (__maxbits + sizeof *__bits * _RWSTD_CHAR_BIT - 1) /
_RWSTD_CHAR_BIT;
+ (__maxbits + _RWSTD_CHAR_BIT - 1) / _RWSTD_CHAR_BIT;
_RWSTD_MEMSET (__bits, 0, __nbytes);
Farid.
Re: [PATCH] bitset.cc (STDCXX-297)
Posted by Martin Sebor <se...@roguewave.com>.
Martin Sebor wrote:
> Farid Zaripov wrote:
>
>> Below is a small patch to resolve issue STDCXX-297:
>
>
> It seems that it would make sense to use the same code here as in
> bitset.cpp. I think that one is "more correct" in that it zeroes
> out all the words (and not just the minimum number of bytes taken
> up by the bitset). Also, I think the code could be simplified as
> follows:
>
> nbytes = (((maxbits | (sizeof *bits * CHAR_BIT - 1)) >> 5)
> + (0 != (maxbits & (sizeof *bits * CHAR_BIT - 1)))) << 2;
With the magic 5 and 2 replaced by expressions parametrized
on sizeof *bits, of course.
>
> What do you think? (Can we do better?)
>
> Martin
>
>>
>> Index: bitset.cc
>> ===================================================================
>> --- bitset.cc (revision 453570)
>> +++ bitset.cc (working copy)
>> @@ -52,7 +52,7 @@
>>
>> // compute the number of bytes occupied by `bits'
>> const _RWSTD_SIZE_T __nbytes =
>> - (__maxbits + sizeof *__bits * _RWSTD_CHAR_BIT - 1) /
>> _RWSTD_CHAR_BIT;
>> + (__maxbits + _RWSTD_CHAR_BIT - 1) / _RWSTD_CHAR_BIT;
>>
>> _RWSTD_MEMSET (__bits, 0, __nbytes);
>>
>>
>> Farid.
>
>
Re: [PATCH] bitset.cc (STDCXX-297)
Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
> Below is a small patch to resolve issue STDCXX-297:
It seems that it would make sense to use the same code here as in
bitset.cpp. I think that one is "more correct" in that it zeroes
out all the words (and not just the minimum number of bytes taken
up by the bitset). Also, I think the code could be simplified as
follows:
nbytes = (((maxbits | (sizeof *bits * CHAR_BIT - 1)) >> 5)
+ (0 != (maxbits & (sizeof *bits * CHAR_BIT - 1)))) << 2;
What do you think? (Can we do better?)
Martin
>
> Index: bitset.cc
> ===================================================================
> --- bitset.cc (revision 453570)
> +++ bitset.cc (working copy)
> @@ -52,7 +52,7 @@
>
> // compute the number of bytes occupied by `bits'
> const _RWSTD_SIZE_T __nbytes =
> - (__maxbits + sizeof *__bits * _RWSTD_CHAR_BIT - 1) /
> _RWSTD_CHAR_BIT;
> + (__maxbits + _RWSTD_CHAR_BIT - 1) / _RWSTD_CHAR_BIT;
>
> _RWSTD_MEMSET (__bits, 0, __nbytes);
>
>
> Farid.