On 2011/06/07 0:27, Michael Stahl wrote:
> refactoring OUString has to be done carefully because it is a central part
> of the URE API/ABI and those must be compatible.
>
> a number of people here have come to the conclusion that it would be an
> improvement to use ::rtl::OString with UTF8 encoding as the standard
> string type, but unfortunately this would be an enormous effort to change,
> and it would mean breaking the backward compatibility of the C++ UNO
> binding, so it was never likely to actually happen.
>
> so far we haven't even got rid of the tools strings... sigh.

I see.

This is just an idea. How about adding a new class besides OUString?

class ZString
{
    sal_Char            *buffer;
    sal_Int32           length;
    sal_uInt16          type;
    rtl_TextEncoding    encoding;
    oslInterlockedCount refCount;
};

 - Gradually shift to the new one ZString, if applicable, in place of OUString 
and OString.
 - "type" might be an ID number denoting "const char*" "char *" "const sal_Unicode 
*", ...
 - "encoding" is an encoding id defined in "rtl/textenc.h"
 - refCount, assignment, copy constructor, ... would be done in the same manner.
 - No encoding conversion will be done until the conversion is really demanded.
 - Use arrays as a memory pool for the fixed-sized structure ZString.
 - ...

e.g
1. String literal that is treated as it is

 ZString a( "xyz" );
   buffer directly points to "xyz"
   no memory allocation neither data copy is involved until encoding conversion 
is demanded.
   length is left uninitialized in this case, but will be measured and cached 
upon being requested.
   type denotes "const char*, zero terminated"
   encoding might be ASCII_US or UTF-8; which might depend on the OS and 
compiler.

 (debugger) print a.buffer  ... prints "xyz"

2. Receiving a result string from a callee in a storage allocated by alloca() 
instead of malloc()

 ZString temp( 100, RTL_ALLOCA );
 func( temp );

 func( ZString& x )
 {
    x = "abc";
 }

 In a destructor of temp above,
   if a reference count is 1, nothing special would be done and the allocated 
memory in the stack area will be automatically freed upon returning to the 
upper frame.
   if a reference count is more than 1, then memory allocation and data copy 
will be involved.

Best,
Tora

On 06.06.11 16:35, tora - Takamichi Akiyama wrote:
Has anyone tried refactoring OUString?

   - It converts iso-8859-1 letters ranging 0x00-0x7f into UCS2 even it is not 
necessary.
   - It requires malloc(), realloc(), and free() or their equivalents.
   - It prevents debugging efforts because of sal_Unicode buffer[1].
   - It mixtures different purposes: passing/returning parameters and 
long-lasting data.
   - and else...
--
-----------------------------------------------------------------
To unsubscribe send email to dev-unsubscr...@openoffice.org
For additional commands send email to sy...@openoffice.org
with Subject: help

Reply via email to