This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: std::string::reserve()
Neil Ferguson wrote:
I've submitted bugzilla report 18654 for this:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18654
Ok, thanks.
I would be delighted to test a patch against my own work; I have a test
suite that happens to exercise the string functionality we use quite a
bit. Unfortunately, I won't be able to get the users to try it,
because (among other things) we have a general rule that we never use
code that didn't come from an "official release". Would that be
acceptable?
Definitely acceptable and I can completely understand that kind of policy.
You can find the one-liner attached: appears to work fine here but you
are the shrink-to-fit power-user, not me ;) The patch is of course
against current mainline, not 3.4, sorry (basic_string is already rather
different). I hope this is not a problem for your own tests.
Soon,
Paolo.
diff -urN libstdc++-v3-orig/include/bits/basic_string.tcc libstdc++-v3/include/bits/basic_string.tcc
--- libstdc++-v3-orig/include/bits/basic_string.tcc 2004-11-24 05:11:09.000000000 +0100
+++ libstdc++-v3/include/bits/basic_string.tcc 2004-11-25 00:39:02.000000000 +0100
@@ -577,7 +577,7 @@
size_type __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep);
const size_type __adj_size = __size + __malloc_header_size;
- if (__adj_size > __pagesize)
+ if (__adj_size > __pagesize && __capacity > __old_capacity)
{
const size_type __extra = __pagesize - __adj_size % __pagesize;
__capacity += __extra / sizeof(_CharT);