diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-08-31 23:00:49 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-09-01 09:53:36 +0100 |
commit | 23854ea235ef32232f34c6ff121f005310f8c01b (patch) | |
tree | 82d2ba080d849cc5cdd801c0d98fc1ccd014ea39 /i18nutil/inc | |
parent | 5e51cc84d9a9885cc081dd409697244dcd7a67c8 (diff) |
refactor x_rtl_uString_new_WithLength to be consistent
i.e. change x_rtl_uString_new_WithLength to always create a rtl_uString
with ref count of 1, like rtl_uString_new_WithLength, so requiring:
either the explicit use of rtl_uString_release or
passing ownership to an OUString via OUString(pStr, SAL_NO_ACQUIRE)
which will do the same in its dtor
Diffstat (limited to 'i18nutil/inc')
-rw-r--r-- | i18nutil/inc/i18nutil/x_rtl_ustring.h | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/i18nutil/inc/i18nutil/x_rtl_ustring.h b/i18nutil/inc/i18nutil/x_rtl_ustring.h index 848cc9e5eb6e..406817a9e7d4 100644 --- a/i18nutil/inc/i18nutil/x_rtl_ustring.h +++ b/i18nutil/inc/i18nutil/x_rtl_ustring.h @@ -38,19 +38,25 @@ * Allocates a new <code>rtl_uString</code> with capacity of nLen + 1 * characters. * - * The reference count is 0. The characters of the capacity are not cleared, + * The reference count is 1. The characters of the capacity are not cleared, * unlike the similar method of rtl_uString_new_WithLength in rtl/ustring.h, so - * is more efficient for allocating a new string. You need to "acquire" by such - * as OUString( rtl_uString * value ) if you intend to use it for a while. + * is more efficient for allocating a new string. + * + * call rtl_uString_release to release the string + * alternatively pass ownership to an OUString with + * rtl::OUString(newStr, SAL_NO_ACQUIRE); + * * @param nLen * @return newStr */ -I18NUTIL_DLLPUBLIC inline rtl_uString * SAL_CALL x_rtl_uString_new_WithLength( sal_Int32 nLen, sal_Int32 _refCount = 0 ) +I18NUTIL_DLLPUBLIC inline rtl_uString * SAL_CALL x_rtl_uString_new_WithLength( sal_Int32 nLen ) { - rtl_uString *newStr = (rtl_uString*) rtl_allocateMemory ( sizeof(rtl_uString) + sizeof(sal_Unicode) * nLen); - newStr->refCount = _refCount; - newStr->length = nLen; - return newStr; + //rtl_uString contains sal_Unicode buffer[1], so an input of nLen allocates + //a buffer of nLen + 1 + rtl_uString *newStr = (rtl_uString*) rtl_allocateMemory ( sizeof(rtl_uString) + sizeof(sal_Unicode) * nLen); + newStr->refCount = 1; + newStr->length = nLen; + return newStr; } /** |