[Libreoffice] [PUSHED] Re: [PATCH] Easy Hacks : Use RTL_CONSTASCII_USTRINGPARAM macro

Caolán McNamara caolanm at redhat.com
Sat Oct 30 12:41:01 PDT 2010

On Sat, 2010-10-30 at 18:16 +0200, Gert Faller wrote:
> I've got 2388 files with 'createFromAscii'. That's a lot.
> The wiki says that this macro is 'faster'. Does it mean at running time ?

Yes, ever so slightly, sal/inc/rtl/ustring.hxx has
OUString::createFromAscii in it, and that calls rtl_uString_newFromAscii
which is in sal/rtl/source/ustring.c and in there you can see that it
has to compute the length of the string, then allocate, and then copy
into it. While using RTL_CONSTASCII_USTRINGPARAM you get the 

    OUString( const sal_Char * value, sal_Int32 length,
              rtl_TextEncoding encoding,
              sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )

constructor which calls rtl_string2UString in sal/rtl/source/ustring.c
and that one only has to allocate and copy the string, skipping the
length of string calculation because that can be calculated in advance
at compile time.

Now, this only works when you can compute the length of the string at
compile time, i.e. its a string literal, so
OUString::createFromAscii("foo") can be trivially replaced, while
OUString::createFromAscii(pSomething) should be left alone.


More information about the LibreOffice mailing list