diff options
author | Oliver-Rainer Wittmann <orw@apache.org> | 2012-11-19 09:10:46 +0000 |
---|---|---|
committer | Oliver-Rainer Wittmann <orw@apache.org> | 2012-11-19 09:10:46 +0000 |
commit | 3e1227e38c424776cd28f9aba625b2ac61221e92 (patch) | |
tree | 8d05321884efc4fe7fde97fd2709841aef0b017c /i18nutil | |
parent | 5fa621198a981ea994d9903298e8a1d884ee686b (diff) |
#121139# - string handling: clear reference counting and passing ownership
Found by: Regina Henschel, Ariel Constenla-Haile
Review by: Herbert Duerr
Notes
Notes:
prefer: 81e16cea9a11185c209894973db8d1990fa9cce6
Diffstat (limited to 'i18nutil')
-rw-r--r-- | i18nutil/inc/i18nutil/x_rtl_ustring.h | 23 | ||||
-rw-r--r-- | i18nutil/source/utility/widthfolding.cxx | 8 |
2 files changed, 9 insertions, 22 deletions
diff --git a/i18nutil/inc/i18nutil/x_rtl_ustring.h b/i18nutil/inc/i18nutil/x_rtl_ustring.h index bdc24f4dc749..89942eb3f9f9 100644 --- a/i18nutil/inc/i18nutil/x_rtl_ustring.h +++ b/i18nutil/inc/i18nutil/x_rtl_ustring.h @@ -32,18 +32,15 @@ /** * Allocates a new <code>rtl_uString</code> which can hold nLen + 1 characters. - * The reference count is 0. The characters of room is not cleared. - * This method is similar to rtl_uString_new_WithLength in rtl/ustring.h, but - * can allocate a new string more efficiently. You need to "acquire" by such as - * OUString( rtl_uString * value ) if you intend to use it for a while. - * @param [output] newStr + * The reference count is 1. The memory allocated for the characters is not initialized. * @param [input] nLen */ -inline void SAL_CALL x_rtl_uString_new_WithLength( rtl_uString ** newStr, sal_Int32 nLen, sal_Int32 _refCount = 0 ) +inline rtl_uString * SAL_CALL x_rtl_uString_new_WithLength( sal_Int32 nLen ) { - *newStr = (rtl_uString*) rtl_allocateMemory ( sizeof(rtl_uString) + sizeof(sal_Unicode) * nLen); - (*newStr)->refCount = _refCount; - (*newStr)->length = nLen; + rtl_uString *newStr = (rtl_uString*) rtl_allocateMemory ( sizeof(rtl_uString) + sizeof(sal_Unicode) * nLen); + newStr->refCount = 1; + newStr->length = nLen; + return newStr; // rtl_uString is defined in rtl/ustring.h as below: //typedef struct _rtl_uString @@ -54,14 +51,6 @@ inline void SAL_CALL x_rtl_uString_new_WithLength( rtl_uString ** newStr, sal_In //} rtl_uString; } -inline rtl_uString * SAL_CALL x_rtl_uString_new_WithLength( sal_Int32 nLen, sal_Int32 _refCount = 0 ) -{ - rtl_uString *newStr = (rtl_uString*) rtl_allocateMemory ( sizeof(rtl_uString) + sizeof(sal_Unicode) * nLen); - newStr->refCount = _refCount; - newStr->length = nLen; - return newStr; -} - /** * Release <code>rtl_uString</code> regardless its reference count. */ diff --git a/i18nutil/source/utility/widthfolding.cxx b/i18nutil/source/utility/widthfolding.cxx index 2b6d365f3937..ee1554d9972e 100644 --- a/i18nutil/source/utility/widthfolding.cxx +++ b/i18nutil/source/utility/widthfolding.cxx @@ -49,8 +49,7 @@ OUString widthfolding::decompose_ja_voiced_sound_marks (const OUString& inStr, s { // Create a string buffer which can hold nCount * 2 + 1 characters. // Its size may become double of nCount. - rtl_uString * newStr; - x_rtl_uString_new_WithLength( &newStr, nCount * 2 ); // defined in x_rtl_ustring.h The reference count is 0 now. + rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount * 2 ); // defined in x_rtl_ustring.h sal_Int32 *p = NULL; sal_Int32 position = 0; @@ -94,7 +93,7 @@ OUString widthfolding::decompose_ja_voiced_sound_marks (const OUString& inStr, s newStr->length = sal_Int32(dst - newStr->buffer); if (useOffset) offset.realloc(newStr->length); - return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1. + return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr> } oneToOneMapping& widthfolding::getfull2halfTable(void) @@ -111,7 +110,6 @@ OUString widthfolding::compose_ja_voiced_sound_marks (const OUString& inStr, sal { // Create a string buffer which can hold nCount + 1 characters. // Its size may become equal to nCount or smaller. - // The reference count is 0 now. rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h // Prepare pointers of unicode character arrays. @@ -199,7 +197,7 @@ OUString widthfolding::compose_ja_voiced_sound_marks (const OUString& inStr, sal } if (useOffset) offset.realloc(newStr->length); - return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1. + return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr> } oneToOneMapping& widthfolding::gethalf2fullTable(void) |