Issue 73908 - in-line rtl[u]String definitions ...
Summary: in-line rtl[u]String definitions ...
Status: REOPENED
Alias: None
Product: porting
Classification: Code
Component: code (show other issues)
Version: 680m197
Hardware: All Linux, all
: P3 Trivial (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-26 14:10 UTC by mmeeks
Modified: 2017-05-20 11:31 UTC (History)
4 users (show)

See Also:
Issue Type: ENHANCEMENT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
patch for posterity (28.36 KB, text/plain)
2007-02-07 12:35 UTC, mmeeks
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description mmeeks 2007-01-26 14:10:42 UTC
So, it would be altogether more pleasant if instead of having to construct
strings from Ascii (with RTL_CONSTASCII_USTRINGPARAM) we could create an
in-line, (and static) rtl_[u]String object, that is in .rodata - hence shared
across all processes, and tagged as 'static' thus, not requiring ref-counting
(cf. #73907#)

This can be done (for gcc at least) nice & conditionally & source compatibly [
Kay's neat idea ]:

/* force expansion */
#define RTL_CONSTASCII_USTRINGPARAM_STR( constAsciiStr ) L##constAsciiStr
/* emit in-line static .rodata rtl_uString */
#define RTL_CONSTASCII_USTRINGPARAM( constAsciiStr ) \
    ((rtl_uString *)(&((const struct { sal_Int32 r; sal_Int32 l; const wchar_t
b[sizeof(constAsciiStr)]; } ) { (1<<30)+1, sizeof(constAsciiStr)-1,
RTL_CONSTASCII_USTRINGPARAM_STR(constAsciiStr) }))), SAL_NO_ACQUIRE
Comment 1 mmeeks 2007-01-26 15:07:49 UTC
committed to salstrintern, ommitting the 'string.hxx' variant, since it causes
grief with (eg.) OStringBuffer.append(), and/or rtl_str_compareWithLength (etc.
etc.) where people used the relevant CONSTASCII macro in the past. Though
changes may be somewhat minimal to clean all callers, at least some work would
be needed.
Comment 2 mmeeks 2007-01-26 15:23:02 UTC
Of course, this helps find some wonderful pieces of code around the place: eg.
the mercifully unused ;-)

--- rdbmaker/inc/codemaker/global.hxx
+++ rdbmaker/inc/codemaker/global.hxx
@@ -94,10 +94,10 @@ sal_Bool fileExists(const ::rtl::OString
 sal_Bool checkFileContent(const ::rtl::OString& targetFileName, const
::rtl::OString& tmpFileName);
 
 const ::rtl::OString inGlobalSet(const ::rtl::OUString & r);
-inline const ::rtl::OString inGlobalSet(sal_Char* p)
-{
-       return inGlobalSet( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(p) ) );
-}

;-)
Comment 3 Stephan Bergmann 2007-01-26 15:32:58 UTC
But wchar_t is often 32 bit, not 16 bit as we would need it.  What am I missing?
Comment 4 mmeeks 2007-01-26 15:41:56 UTC
sb: you're missing the solenv/inc/ patch:

CFLAGS+=-fshort-wchar -DRTL_INLINE_STRINGS
CFLAGSCXX+=-fshort-wchar -DRTL_INLINE_STRINGS

:-) and the fact that this is a source-transparent optimisation we turn on
conditionally only where it works.
Comment 5 Stephan Bergmann 2007-01-26 16:06:31 UTC
Strictly speaking, this breaks a stable API, as RTL_CONSTASCII_USTRINGPARAM is
documented to "Supply an ASCII string literal together with its length and text
encoding."  ;)
Comment 6 kay.ramme 2007-01-26 16:13:30 UTC
Alternative would be, to introduce a new macro with the desired spec. and to
adapt all (possible) locations of RTL_CONSTASCII_USTRINGPARAM ....

IMHO, the risk is relatively low, so we might want to take it ... ;-)
Comment 7 Stephan Bergmann 2007-01-26 21:41:03 UTC
1  -fshort-wchar:  Somewhat thin ice.  At least libstd++ and libstlport shipped
with OOo export wchar_t-infected C++ functionality.  You can only hope that
nobody uses it.  And libstlport is a public part of URE, so it should not change
incompatibly, so we should not build it with -fshort-wchar.

2  "IMHO, the risk is relatively low"  I think so too (hence the smiley). 
However, the documentation of RTL_CONSTASCII_USTRINGPARAM should be changed to
state that it expands to an argument list suitable for a call to exactly one of
the rtl::OUString constructors.
Comment 8 mmeeks 2007-01-29 10:46:13 UTC
2. wrt. the risk, I'm building up a patch of the changes necessary around the
place - and it seems, they are becoming more substantial, which is a problem.
Particularly in places where an attempt has been made to optimise string usage
already - eg. 'xmloff' constructs are used that make this harder.

What might be better would be to use a macro that had control over the OUString
construction too [ and resign ourselves to more 'global' OUStrings (?) ], ie.

RTL_USTRING_LITERAL("foo") -> either OUString("foo", sizeof("foo")-1, ASCII), or
OUString(mangled_macro("foo"), SAL_NO_ACQUIRE)

That way perhaps we would have more joy, and it'd be more compatible; it'd also
have the merit of being rather shorter than the existing OUString(
RTL_VERY_LONG_NAME_INDEED ("foo")) - what do you think ?
Comment 9 mmeeks 2007-02-07 12:26:25 UTC
Hokay - I'm backing this out of the CWS - for several reasons:

* it doesn't work as is:
   + We really need a macro (eg.) RTL_USTRING_LITERAL(a) that will
     include the OUString() creation, then use that in hot-spots.

* it doesn't save that much memory:
   + much of the string duplication I've measured is removed by using
     'intern' anyway, worse using it will increase the size of the
     binaries by more than the heap we will save, since at a given time
     most strings are not instantiated on the heap.

* shlib unloading (normal lifecycle problem)
   + if we pass references to .rodata static strings around the app,
     then we can never unload that library again, ergo we should do
     this sparingly where we can prove there is a useful win I think.

And of course, I don't want the problems to block the 'intern' feature getting
integrated :-)
Comment 10 mmeeks 2007-02-07 12:35:16 UTC
Created attachment 42822 [details]
patch for posterity
Comment 11 caolanm 2010-01-05 09:32:35 UTC
As an aside new C++ standard will have new string literals of...

u8"UTF-8 string."
u"UTF-16 string."
U"UTF-32 string."
Comment 12 Marcus 2017-05-20 11:31:16 UTC
Reset assigne to the default "issues@openoffice.apache.org".