------- Comment #3 from pcarlini at suse dot de 2006-09-12 17:31 ------- Yes, I understand. But consider another scenario were, after the initial assignment, you are not adding anything more later on (in the loop, in your case): doing a shallow copy (changing only the reference count) means a super-fast operation, no memory allocations at all, no copies of actual chars. On the other hand, as soon as you start using c_str no reference counts are involved and in the initial assignment all the chars of current.FileName are actually copied.
In other terms, the general "hope" for a reference-counted string is that, as long as the internal buffer of the string grows sufficiently fast upon += (and indeed it does, doubling each time), an initial resize (*) should not be used at all and the string should be just let grow according to its internal logic. (*) Note that, in any case, if I understand correctly the code, you want a *reserve* not a resize (which is much slower, also does a memset, basically) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29037