About Strings

Stephan Bergmann sbergman at redhat.com
Mon Mar 19 05:46:44 PDT 2012


On 03/19/2012 07:30 AM, Noel Grandin wrote:
> Even in Java, it's a code smell to allocate a StringBuffer object
> without specifying a pre-allocation size.

Is it?

> Might make a good EasyHack to go through the code and change the places
> that allocate OUStringBuffer to give them a reasonable initial size?

Problem is, with the various (incl. signed vs. unsigned) integral types 
around, it is often not easy to write an expression for initial 
rtl::OUStringBuffer capacity that is both reasonably short and correct 
(i.e., not prone to trigger undefined behaviour for signed sal_Int32) -- 
and also does not cause warnings when compiled on any platform.

Therefore, it is often much simpler to go without a pre-computed 
capacity and accept the log N reallocation hit.

Stephan


More information about the LibreOffice mailing list