This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Fwd: basic_string<> - useless because of its poor performance]
- To: Ryszard Kabatek <Ryszard dot Kabatek at softax dot pl>
- Subject: Re: [Fwd: basic_string<> - useless because of its poor performance]
- From: Carlo Wood <carlo at alinoe dot com>
- Date: Fri, 6 Jul 2001 16:49:18 +0200
- Cc: Loren James Rittle <rittle at latour dot rsch dot comm dot mot dot com>, libstdc++ at gcc dot gnu dot org
- References: <200107052215.f65MFXg63071@latour.rsch.comm.mot.com> <3B455CEA.E140F72@softax.pl>
On Fri, Jul 06, 2001 at 08:38:34AM +0200, Ryszard Kabatek wrote:
> size_type
> get_new_capacity(size_type n,
> size_type max_len)
> {
> if (n > max_len) // OK, we get an exception in _Rep::_S_create
> return n;
>
> size_type result = n < 17 ? 32 : 2*n;
> return result < max_len ? result : max_len; // Avoiding an exception in _Rep::_S_create
> }
Hmm. How about:
size_type
get_new_capacity(size_type n,
size_type max_len)
{
// Not sure if this is still correct:
if (n > max_len) // OK, we get an exception in _Rep::_S_create
return n;
const size_type l2 = 5; // 5 == 2log(32), 32 is the minimum size.
size_type l = (n < __page_size ? n : __page_size) + __malloc_header_size - 1;
if (l >= __page_size - 1)
n = (((n - 1) >> __log_page_size) + 1) << __log_page_size; // __log_page_size == 2log(__page_size).
else
for (n = 1 << l2, l >>= l2; l > 0; n <<= 1)
l >>= 1;
size_type result = n - __malloc_header_size;
return result < max_len ? result : max_len; // Avoiding an exception in _Rep::_S_create
}
I am not sure if I understand it correctly however: does this function
return the new __capacity, or is this what is passed directly to malloc()?
This implementation assumes that the result is passed directly to malloc().
I have the feeling it should contain sizeof(CharT) and sizeof(_Rep) somehow though :/
This function is not as trivial as it looks.
--
Carlo Wood <carlo@alinoe.com>