Kaydet (Commit) 1426d443 authored tarafından Michael Meeks's avatar Michael Meeks

sal: expose more stringbuffer related instrumentation points

Avoid ref/unref pair in makeStringAndClear, hook into the
stringbuffer-like 'String' class to expose it's conversion to
immutable strings, and fixup misc. missing instrumentation.
üst 0f330ea2
......@@ -179,6 +179,34 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uStringbuffer_remove(
sal_Int32 start,
sal_Int32 len );
/**
Returns an immutable rtl_uString object, while clearing the string buffer.
This method is primarily used to allow these completed
string allocation events to be traced.
@param ppThis The string, on that the operation should take place
@param nCapacity pointer to the capacity of the string buffer
@since LibreOffice 3.6
*/
SAL_DLLPUBLIC rtl_uString * SAL_CALL rtl_uStringBuffer_makeStringAndClear(
/*inout*/ rtl_uString ** ppThis,
sal_Int32 *nCapacity );
/**
References and returns an immutable rtl_uString object, from a mutable
string-buffer object.
This method is primarily used to allow legacy 'String' class
conversions to OUString to be accurately traced.
@param pThis The string, on that the operation should take place
@since LibreOffice 3.6
*/
SAL_DLLPUBLIC rtl_uString * SAL_CALL rtl_uStringBuffer_refReturn( rtl_uString *pThis );
#ifdef __cplusplus
}
#endif
......
......@@ -181,10 +181,9 @@ public:
*/
OUString makeStringAndClear()
{
OUString aRet( pData );
rtl_uString_new(&pData);
nCapacity = 0;
return aRet;
return OUString(
rtl_uStringBuffer_makeStringAndClear( &pData, &nCapacity ),
SAL_NO_ACQUIRE );
}
/**
......
......@@ -54,6 +54,24 @@ sal_Int16 rtl_ImplGetDigit( sal_Unicode ch, sal_Int16 nRadix );
sal_Bool rtl_ImplIsWhitespace( sal_Unicode c );
// string lifetime instrumentation / diagnostics
#if 0
# include <rtl/ustring.hxx>
# define RTL_LOG_STRING_NEW(s) \
do { \
fprintf (stderr, "+%s\n", \
rtl::OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()); \
} while (0)
# define RTL_LOG_STRING_DELETE(s) \
do { \
fprintf (stderr, "-%s\n", \
rtl::OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()); \
} while (0)
#else
# define RTL_LOG_STRING_NEW(s)
# define RTL_LOG_STRING_DELETE(s)
#endif
#endif /* INCLUDED_RTL_SOURCE_STRIMP_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -71,6 +71,11 @@ static rtl_String const aImplEmpty_rtl_String =
#define IMPL_RTL_STRINGDATA rtl_String
#define IMPL_RTL_EMPTYSTRING aImplEmpty_rtl_String
#undef RTL_LOG_STRING_NEW
#define RTL_LOG_STRING_NEW(s)
#undef RTL_LOG_STRING_DELETE
#define RTL_LOG_STRING_DELETE(s)
/* ======================================================================= */
/* Include String/UString template code */
......
......@@ -49,12 +49,6 @@ inline void rtl_str_ImplCopy( IMPL_RTL_STRCODE* pDest,
}
*/
// for instrumentation / diagnostics
#ifndef RTL_LOG_STRING_NEW
# define RTL_LOG_STRING_NEW(s)
# define RTL_LOG_STRING_DELETE(s)
#endif
#define rtl_str_ImplCopy( _pDest, _pSrc, _nCount ) \
{ \
IMPL_RTL_STRCODE* __mm_pDest = _pDest; \
......@@ -1096,10 +1090,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( new_WithLength )( IMPL_RTL_STRINGDATA** ppThi
OSL_ASSERT(*ppThis != NULL);
(*ppThis)->length = 0;
{
IMPL_RTL_STRCODE* pTempStr = (*ppThis)->buffer;
memset(pTempStr, 0, nLen*sizeof(IMPL_RTL_STRCODE));
}
}
}
......
......@@ -656,6 +656,7 @@ void SAL_CALL rtl_uriEncode(rtl_uString * pText, sal_Bool const * pCharClass,
break;
}
}
*pResult = rtl_uStringBuffer_makeStringAndClear( pResult, &nCapacity );
}
void SAL_CALL rtl_uriDecode(rtl_uString * pText,
......@@ -702,6 +703,7 @@ void SAL_CALL rtl_uriDecode(rtl_uString * pText,
break;
}
}
*pResult = rtl_uStringBuffer_makeStringAndClear( pResult, &nCapacity );
}
break;
}
......
......@@ -28,20 +28,10 @@
#include <osl/interlck.h>
#ifndef _RTL_STRING_HXX_
#include <rtl/ustrbuf.hxx>
#endif
#include <rtl/memory.h>
#include <strimp.hxx>
/*
#include <rtl/alloc.h>
*/
/*************************************************************************
* rtl_uStringbuffer_newFromStr_WithLength
*/
void SAL_CALL rtl_uStringbuffer_newFromStr_WithLength( rtl_uString ** newStr,
const sal_Unicode * value,
sal_Int32 count)
......@@ -55,12 +45,32 @@ void SAL_CALL rtl_uStringbuffer_newFromStr_WithLength( rtl_uString ** newStr,
rtl_uString_new_WithLength( newStr, count + 16 );
(*newStr)->length = count;
rtl_copyMemory( (*newStr)->buffer, value, count * sizeof(sal_Unicode));
RTL_LOG_STRING_NEW( *newStr );
return;
}
/*************************************************************************
* rtl_uStringbuffer_newFromStringBuffer
*/
rtl_uString * SAL_CALL rtl_uStringBuffer_refReturn( rtl_uString * pThis )
{
RTL_LOG_STRING_NEW( pThis );
rtl_uString_acquire( pThis );
return pThis;
}
rtl_uString * SAL_CALL rtl_uStringBuffer_makeStringAndClear( rtl_uString ** ppThis,
sal_Int32 *nCapacity )
{
// avoid an un-necessary atomic ref/unref pair
rtl_uString *pStr = *ppThis;
*ppThis = NULL;
rtl_uString_new (ppThis);
*nCapacity = 0;
RTL_LOG_STRING_NEW( pStr );
return pStr;
}
sal_Int32 SAL_CALL rtl_uStringbuffer_newFromStringBuffer( rtl_uString ** newStr,
sal_Int32 capacity,
rtl_uString * oldStr )
......@@ -76,12 +86,10 @@ sal_Int32 SAL_CALL rtl_uStringbuffer_newFromStringBuffer( rtl_uString ** newStr,
(*newStr)->length = oldStr->length;
rtl_copyMemory( (*newStr)->buffer, oldStr->buffer, oldStr->length * sizeof(sal_Unicode));
}
RTL_LOG_STRING_NEW( *newStr );
return newCapacity;
}
/*************************************************************************
* rtl_uStringbuffer_ensureCapacity
*/
void SAL_CALL rtl_uStringbuffer_ensureCapacity
(rtl_uString ** This, sal_Int32* capacity, sal_Int32 minimumCapacity)
{
......@@ -99,13 +107,12 @@ void SAL_CALL rtl_uStringbuffer_ensureCapacity
*This = pNew;
rtl_copyMemory( (*This)->buffer, pTmp->buffer, pTmp->length * sizeof(sal_Unicode) );
RTL_LOG_STRING_NEW( pTmp ); // with accurate contents
rtl_uString_release( pTmp );
}
}
/*************************************************************************
* rtl_uStringbuffer_insert
*/
void SAL_CALL rtl_uStringbuffer_insert( rtl_uString ** This,
sal_Int32 * capacity,
sal_Int32 offset,
......@@ -165,9 +172,6 @@ void rtl_uStringbuffer_insertUtf32(
rtl_uStringbuffer_insert(pThis, capacity, offset, buf, len);
}
/*************************************************************************
* rtl_uStringbuffer_insert_ascii
*/
void SAL_CALL rtl_uStringbuffer_insert_ascii( /*inout*/rtl_uString ** This,
/*inout*/sal_Int32 * capacity,
sal_Int32 offset,
......
......@@ -79,20 +79,6 @@ static rtl_uString const aImplEmpty_rtl_uString =
#define IMPL_RTL_INTERN
static void internRelease (rtl_uString *pThis);
#if 0 // string lifetime / logging debug
# include <rtl/ustring.hxx>
# define RTL_LOG_STRING_NEW(s) \
do { \
fprintf (stderr, "+%s\n", \
rtl::OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()); \
} while (0)
# define RTL_LOG_STRING_DELETE(s) \
do { \
fprintf (stderr, "-%s\n", \
rtl::OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()); \
} while (0)
#endif
/* ======================================================================= */
/* Include String/UString template code */
......@@ -700,6 +686,7 @@ static void rtl_string2UString_status( rtl_uString** ppThis,
if (pInfo != NULL) {
*pInfo = 0;
}
RTL_LOG_STRING_NEW( *ppThis );
return;
}
}
......
......@@ -623,6 +623,8 @@ LIBO_UDK_3.6 { # symbols available in >= LibO 3.6
rtl_uString_newReplaceFirst;
rtl_uString_newReplaceFirstAsciiL;
rtl_uString_newReplaceFirstAsciiLAsciiL;
rtl_uStringBuffer_refReturn;
rtl_uStringBuffer_makeStringAndClear;
} UDK_3.10;
PRIVATE_1.0 {
......
......@@ -33,6 +33,7 @@
#include <osl/thread.h>
#include <rtl/textenc.h>
#include <rtl/textcvt.h>
#include <rtl/ustrbuf.h>
#include <rtl/string.hxx>
#include <rtl/ustring.hxx>
#include "tools/toolsdllapi.h"
......@@ -173,7 +174,8 @@ public:
operator rtl::OUString () const
{
return rtl::OUString (reinterpret_cast<rtl_uString*>(mpData));
return rtl::OUString( rtl_uStringBuffer_refReturn(
reinterpret_cast<rtl_uString*>(mpData)), SAL_NO_ACQUIRE );
}
static UniString CreateFromAscii( const sal_Char* pAsciiStr );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment