[patch/rfa] Tiny but delicate change to string::_M_mutate
Paolo Carlini
pcarlini@suse.de
Fri Oct 15 18:25:00 GMT 2004
Hi everyone, hi Nathan,
I like a lot this tweak but I'm not going to apply it if Nathan is not
able to double check it: is very small but delicate.
Basically, when Nathan improved last year the _S_empty_rep treatment
(not ref-counted anymore) he added another case in the conditional
at the beginning of _M_mutate:
if (_M_rep() == &_S_empty_rep || __new_size > capacity() ...
Therefore, what change is that we reallocate even when __new_size ==
capacity(). However, that seems not necessary, since, in that case,
we have simply another empty string (for the empty_rep, capacity() == 0,
of course). If we remove the new case, nothing happens in _M_mutate,
besides eventually reconfirming the sharable state for the empty string
object, length == 0 and _Rep::_S_terminal in position zero, the default
contents, in other terms.
Nathan, can you spot any flaw in my reasoning? If the idea works we
obtain, not only a slightly simpler _M_mutate, but, more importantly,
we keep on using the empty_rep trick even after things like
string str;
str.append(0, 'x');
which currently leads to normal dynamically allocated memory.
(Of course regtested, on x86-linux, for now)
Paolo.
//////////////
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CL_mutate
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20041015/90b3e0fa/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch_mutate
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20041015/90b3e0fa/attachment-0001.ksh>
More information about the Libstdc++
mailing list