|
|
|
|
|
by CJefferson
4662 days ago
|
|
Code written in Java would have exactly the same problem I believe? You are advised to use a StringBuilder. C++ has a StringBuilder, it's called std::ostringstream, but the author didn't seem to know about it, so reinvented it. To be polite, his reinvention is reasonable, and knowing about this problem is useful. |
|
For example it may create a new StringBuilder in every iteration of a loop whereas you may be able to code it such that only a single StringBuilder needs to be created and you may be able to provide better initial array size hinting. If it's just a single concatenation statement, building a log message or something, then using the '+' operator won't have much if any impact on performance.