Date: prev next · Thread: first prev next last
2010 Archives by date, by thread · List index


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.

C.


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.