From e6f4779de8fea16931967ce206439c5780d46125 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 24 Aug 2018 16:32:42 +0200 Subject: directly use malloc/free in sal, instead of rtl_allocateMemory/etc now that those functions are entirely malloc/free based, we can skip a function call layer. Change-Id: Ib091de0bdf4cdd58cee45185df17d96d3e8af402 Reviewed-on: https://gerrit.libreoffice.org/59576 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sal/rtl/bootstrap.cxx | 4 ++-- sal/rtl/byteseq.cxx | 18 +++++++++--------- sal/rtl/cipher.cxx | 4 ++-- sal/rtl/cmdargs.cxx | 2 +- sal/rtl/digest.cxx | 13 +++++++------ sal/rtl/locale.cxx | 26 +++++++++++++------------- sal/rtl/math.cxx | 4 ++-- sal/rtl/strimp.cxx | 10 +++++----- sal/rtl/strimp.hxx | 2 +- 9 files changed, 42 insertions(+), 41 deletions(-) (limited to 'sal/rtl') diff --git a/sal/rtl/bootstrap.cxx b/sal/rtl/bootstrap.cxx index a802da6a562c..ac735caf713b 100644 --- a/sal/rtl/bootstrap.cxx +++ b/sal/rtl/bootstrap.cxx @@ -320,9 +320,9 @@ struct Bootstrap_Impl ~Bootstrap_Impl(); static void * operator new (std::size_t n) - { return rtl_allocateMemory (sal_uInt32(n)); } + { return malloc (sal_uInt32(n)); } static void operator delete (void * p , std::size_t) - { rtl_freeMemory (p); } + { free (p); } bool getValue( rtl::OUString const & key, rtl_uString ** value, diff --git a/sal/rtl/byteseq.cxx b/sal/rtl/byteseq.cxx index d0c77b5dc1ed..64f815b4d73b 100644 --- a/sal/rtl/byteseq.cxx +++ b/sal/rtl/byteseq.cxx @@ -19,12 +19,12 @@ #include #include +#include #include #include #include -#include /* static data to be referenced by all empty strings * the refCount is predefined to 1 and must never become 0 ! @@ -50,17 +50,17 @@ void SAL_CALL rtl_byte_sequence_reference2One( nElements = pSequence->nElements; if (nElements) { - pNew = static_cast(rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE + nElements )); + pNew = static_cast(malloc( SAL_SEQUENCE_HEADER_SIZE + nElements )); if ( pNew != nullptr ) memcpy( pNew->elements, pSequence->elements, nElements ); if (! osl_atomic_decrement( &pSequence->nRefCount )) - rtl_freeMemory( pSequence ); + free( pSequence ); } else { - pNew = static_cast(rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE )); + pNew = static_cast(malloc( SAL_SEQUENCE_HEADER_SIZE )); } if ( pNew != nullptr ) @@ -88,7 +88,7 @@ void SAL_CALL rtl_byte_sequence_realloc( if (pSequence->nRefCount > 1) // split { - pNew = static_cast(rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE + nSize )); + pNew = static_cast(malloc( SAL_SEQUENCE_HEADER_SIZE + nSize )); if ( pNew != nullptr ) { @@ -104,12 +104,12 @@ void SAL_CALL rtl_byte_sequence_realloc( } if (! osl_atomic_decrement( &pSequence->nRefCount )) - rtl_freeMemory( pSequence ); + free( pSequence ); pSequence = pNew; } else { - pSequence = static_cast(rtl_reallocateMemory( + pSequence = static_cast(realloc( pSequence, SAL_SEQUENCE_HEADER_SIZE + nSize )); } @@ -136,7 +136,7 @@ void SAL_CALL rtl_byte_sequence_release( sal_Sequence *pSequence ) { if (! osl_atomic_decrement( &(pSequence->nRefCount )) ) { - rtl_freeMemory( pSequence ); + free( pSequence ); } } } @@ -178,7 +178,7 @@ void SAL_CALL rtl_byte_sequence_constructNoDefault( sal_Sequence **ppSequence , *ppSequence = nullptr; } - *ppSequence = static_cast(rtl_allocateMemory( SAL_SEQUENCE_HEADER_SIZE + nLength )); + *ppSequence = static_cast(malloc( SAL_SEQUENCE_HEADER_SIZE + nLength )); if ( *ppSequence != nullptr ) { diff --git a/sal/rtl/cipher.cxx b/sal/rtl/cipher.cxx index 96cb896623e1..3041d865b7b0 100644 --- a/sal/rtl/cipher.cxx +++ b/sal/rtl/cipher.cxx @@ -1138,7 +1138,7 @@ void SAL_CALL rtl_cipher_destroyBF(rtlCipher Cipher) SAL_THROW_EXTERN_C() rtl_freeZeroMemory(pImpl, sizeof(CipherBF_Impl)); } else - rtl_freeMemory(pImpl); + free(pImpl); } } @@ -1409,7 +1409,7 @@ void SAL_CALL rtl_cipher_destroyARCFOUR(rtlCipher Cipher) SAL_THROW_EXTERN_C() rtl_freeZeroMemory(pImpl, sizeof(CipherARCFOUR_Impl)); } else - rtl_freeMemory(pImpl); + free(pImpl); } } diff --git a/sal/rtl/cmdargs.cxx b/sal/rtl/cmdargs.cxx index 8e10b0bca04d..3c3069f4fd6a 100644 --- a/sal/rtl/cmdargs.cxx +++ b/sal/rtl/cmdargs.cxx @@ -37,7 +37,7 @@ ArgHolder::~ArgHolder() while (g_nCommandArgCount > 0) rtl_uString_release (g_ppCommandArgs[--g_nCommandArgCount]); - rtl_freeMemory (g_ppCommandArgs); + free (g_ppCommandArgs); g_ppCommandArgs = nullptr; } diff --git a/sal/rtl/digest.cxx b/sal/rtl/digest.cxx index fbacbc9838dd..3bd2dfa214dd 100644 --- a/sal/rtl/digest.cxx +++ b/sal/rtl/digest.cxx @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -430,7 +431,7 @@ void SAL_CALL rtl_digest_destroyMD2(rtlDigest Digest) SAL_THROW_EXTERN_C() if (pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmMD2) rtl_freeZeroMemory(pImpl, sizeof(DigestMD2_Impl)); else - rtl_freeMemory(pImpl); + free(pImpl); } } @@ -813,7 +814,7 @@ void SAL_CALL rtl_digest_destroyMD5(rtlDigest Digest) SAL_THROW_EXTERN_C() if (pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmMD5) rtl_freeZeroMemory(pImpl, sizeof(DigestMD5_Impl)); else - rtl_freeMemory(pImpl); + free(pImpl); } } @@ -1227,7 +1228,7 @@ void SAL_CALL rtl_digest_destroySHA(rtlDigest Digest) SAL_THROW_EXTERN_C() if (pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmSHA) rtl_freeZeroMemory(pImpl, sizeof(DigestSHA_Impl)); else - rtl_freeMemory(pImpl); + free(pImpl); } } @@ -1387,7 +1388,7 @@ void SAL_CALL rtl_digest_destroySHA1(rtlDigest Digest) SAL_THROW_EXTERN_C() if (pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmSHA1) rtl_freeZeroMemory(pImpl, sizeof(DigestSHA_Impl)); else - rtl_freeMemory(pImpl); + free(pImpl); } } @@ -1584,7 +1585,7 @@ void SAL_CALL rtl_digest_destroyHMAC_MD5(rtlDigest Digest) SAL_THROW_EXTERN_C() if (pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmHMAC_MD5) rtl_freeZeroMemory(pImpl, sizeof(DigestHMAC_MD5_Impl)); else - rtl_freeMemory(pImpl); + free(pImpl); } } @@ -1781,7 +1782,7 @@ void SAL_CALL rtl_digest_destroyHMAC_SHA1(rtlDigest Digest) if (pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmHMAC_SHA1) rtl_freeZeroMemory(pImpl, sizeof(DigestHMAC_SHA1_Impl)); else - rtl_freeMemory(pImpl); + free(pImpl); } } diff --git a/sal/rtl/locale.cxx b/sal/rtl/locale.cxx index b6b5ee499141..3fb85e1b8bb7 100644 --- a/sal/rtl/locale.cxx +++ b/sal/rtl/locale.cxx @@ -17,10 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include #include #include -#include #include @@ -56,8 +56,8 @@ extern "C" void rtl_hashentry_destroy(RTL_HASHENTRY* entry) if (entry->Next) rtl_hashentry_destroy(entry->Next); - rtl_freeMemory(entry->Entry); - rtl_freeMemory(entry); + free(entry->Entry); + free(entry); } extern "C" void rtl_hashtable_destroy(RTL_HASHTABLE* table) @@ -77,8 +77,8 @@ extern "C" void rtl_hashtable_destroy(RTL_HASHTABLE* table) size--; } - rtl_freeMemory(table->Table); - rtl_freeMemory(table); + free(table->Table); + free(table); } extern "C" void rtl_hashtable_init(RTL_HASHTABLE** table, sal_Int8 sizeIndex) @@ -88,12 +88,12 @@ extern "C" void rtl_hashtable_init(RTL_HASHTABLE** table, sal_Int8 sizeIndex) if (*table) rtl_hashtable_destroy(*table); - *table = static_cast< RTL_HASHTABLE* >(rtl_allocateMemory(sizeof(RTL_HASHTABLE))); + *table = static_cast< RTL_HASHTABLE* >(malloc(sizeof(RTL_HASHTABLE))); (*table)->iSize = sizeIndex; (*table)->Size = nSize; (*table)->Elements = 0; - (*table)->Table = static_cast< RTL_HASHENTRY** >(rtl_allocateMemory((*table)->Size * sizeof(RTL_HASHENTRY*))); + (*table)->Table = static_cast< RTL_HASHENTRY** >(malloc((*table)->Size * sizeof(RTL_HASHENTRY*))); while (nSize) { @@ -130,7 +130,7 @@ extern "C" rtl_Locale* rtl_hashtable_add(RTL_HASHTABLE** table, rtl_Locale* valu pEntry = &(*pEntry)->Next; } - RTL_HASHENTRY *newEntry = static_cast< RTL_HASHENTRY* >(rtl_allocateMemory(sizeof(RTL_HASHENTRY))); + RTL_HASHENTRY *newEntry = static_cast< RTL_HASHENTRY* >(malloc(sizeof(RTL_HASHENTRY))); newEntry->Entry = value; newEntry->Next = nullptr; *pEntry = newEntry; @@ -158,18 +158,18 @@ sal_Bool rtl_hashtable_grow(RTL_HASHTABLE** table) { rtl_hashtable_add(&pNewTable, pEntry->Next->Entry); pNext = pEntry->Next; - rtl_freeMemory(pEntry); + free(pEntry); pEntry = pNext; } - rtl_freeMemory(pEntry); + free(pEntry); } i++; } - rtl_freeMemory((*table)->Table); - rtl_freeMemory(*table); + free((*table)->Table); + free(*table); (*table) = pNewTable; return true; @@ -247,7 +247,7 @@ rtl_Locale * SAL_CALL rtl_locale_register(const sal_Unicode * language, const sa rtl_uString_newFromStr(&sCountry, country); rtl_uString_newFromStr(&sVariant, variant); - newLocale = static_cast(rtl_allocateMemory( sizeof(rtl_Locale) )); + newLocale = static_cast(malloc( sizeof(rtl_Locale) )); newLocale->Language = sLanguage; newLocale->Country = sCountry; diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx index 7b172f1ee1d2..12571baf4b86 100644 --- a/sal/rtl/math.cxx +++ b/sal/rtl/math.cxx @@ -464,7 +464,7 @@ inline void doubleToString(typename T::String ** pResult, if (nBuf > nBufMax) { pBuf = static_cast< typename T::Char * >( - rtl_allocateMemory(nBuf * sizeof (typename T::Char))); + malloc(nBuf * sizeof (typename T::Char))); OSL_ENSURE(pBuf, "Out of memory"); } else @@ -707,7 +707,7 @@ inline void doubleToString(typename T::String ** pResult, T::appendChars(pResult, pResultCapacity, &nResultOffset, pBuf, p - pBuf); if (pBuf != &aBuf[0]) - rtl_freeMemory(pBuf); + free(pBuf); } } diff --git a/sal/rtl/strimp.cxx b/sal/rtl/strimp.cxx index d1651a2ad1d7..51a1a94bd705 100644 --- a/sal/rtl/strimp.cxx +++ b/sal/rtl/strimp.cxx @@ -65,11 +65,11 @@ bool rtl_ImplIsWhitespace( sal_Unicode c ) */ static rtl_arena_type *pre_arena = nullptr; -rtl_allocateStringFn rtl_allocateString = rtl_allocateMemory; -rtl_freeStringFn rtl_freeString = rtl_freeMemory; +rtl_allocateStringFn rtl_allocateString = malloc; +rtl_freeStringFn rtl_freeString = free; extern "C" { -static void *pre_allocateStringFn(sal_Size n) +static void *pre_allocateStringFn(size_t n) { sal_Size size = RTL_MEMORY_ALIGN(n + 4, 4); char *addr = static_cast(rtl_arena_alloc(pre_arena, &size)); @@ -110,8 +110,8 @@ void SAL_CALL rtl_alloc_preInit (sal_Bool start) SAL_THROW_EXTERN_C() else { rtl_arena_foreach(pre_arena, mark_static); - rtl_allocateString = rtl_allocateMemory; - rtl_freeString = rtl_freeMemory; + rtl_allocateString = malloc; + rtl_freeString = free; // TODO: also re-initialize main allocator as well. } diff --git a/sal/rtl/strimp.hxx b/sal/rtl/strimp.hxx index b3446db1fdb2..f3516f7999bd 100644 --- a/sal/rtl/strimp.hxx +++ b/sal/rtl/strimp.hxx @@ -56,7 +56,7 @@ rtl_String* rtl_string_ImplAlloc( sal_Int32 nLen ); extern "C" { -typedef void *(*rtl_allocateStringFn)(sal_Size size); +typedef void *(SAL_CALL * rtl_allocateStringFn)(size_t size); typedef void (*rtl_freeStringFn)(void *); } -- cgit v1.2.3