From 090d683489bfa3f36f1e2624c310ff9ca5836038 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 12 Mar 2015 13:33:31 -0700 Subject: Kill CFX_GrowOnlyPool. It's unused, and when the time comes, we'll want to put pdfium onto a hardened allocator like partitionAlloc anyways. Along the way, merge adjacent #ifdef __cplusplus blocks, remove a pointless check for __cplusplus inside a .cpp file, and remove a redundant cast. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1008483002 --- core/include/fxcrt/fx_memory.h | 46 ++----------------------------- core/src/fxcrt/fx_basic_memmgr.cpp | 55 ++++---------------------------------- 2 files changed, 7 insertions(+), 94 deletions(-) diff --git a/core/include/fxcrt/fx_memory.h b/core/include/fxcrt/fx_memory.h index cb71c04fca..8806bba7dd 100644 --- a/core/include/fxcrt/fx_memory.h +++ b/core/include/fxcrt/fx_memory.h @@ -65,12 +65,9 @@ public: } void operator delete (void*, void*) {} }; -#endif -#ifdef __cplusplus #if defined(_DEBUG) #define FX_NEW new(__FILE__, __LINE__) #else - #define FX_NEW new #endif #define FX_NEW_VECTOR(Pointer, Class, Count) \ @@ -91,44 +88,5 @@ public: virtual ~CFX_DestructObject() {} }; -class CFX_GrowOnlyPool : public CFX_Object -{ -public: - - CFX_GrowOnlyPool(size_t trunk_size = 16384); - - ~CFX_GrowOnlyPool(); - - void SetTrunkSize(size_t trunk_size) - { - m_TrunkSize = trunk_size; - } - - void* AllocDebug(size_t size, FX_LPCSTR file, int line) - { - return Alloc(size); - } - - void* Alloc(size_t size); - - void* ReallocDebug(void* p, size_t new_size, FX_LPCSTR file, int line) - { - return NULL; - } - - void* Realloc(void* p, size_t new_size) - { - return NULL; - } - - void Free(void*) {} - - void FreeAll(); -private: - - size_t m_TrunkSize; - - void* m_pFirstTrunk; -}; -#endif -#endif +#endif // __cplusplus +#endif // _FX_MEMORY_H_ diff --git a/core/src/fxcrt/fx_basic_memmgr.cpp b/core/src/fxcrt/fx_basic_memmgr.cpp index 3b3211c20f..6538ea6a70 100644 --- a/core/src/fxcrt/fx_basic_memmgr.cpp +++ b/core/src/fxcrt/fx_basic_memmgr.cpp @@ -5,12 +5,12 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "../../include/fxcrt/fx_basic.h" -#ifdef __cplusplus + extern "C" { -#endif + void* FXMEM_DefaultAlloc(size_t byte_size, int flags) { - return (void*)malloc(byte_size); + return malloc(byte_size); } void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags) { @@ -20,50 +20,5 @@ void FXMEM_DefaultFree(void* pointer, int flags) { free(pointer); } -#ifdef __cplusplus -} -#endif -CFX_GrowOnlyPool::CFX_GrowOnlyPool(size_t trunk_size) -{ - m_TrunkSize = trunk_size; - m_pFirstTrunk = NULL; -} -CFX_GrowOnlyPool::~CFX_GrowOnlyPool() -{ - FreeAll(); -} -struct _FX_GrowOnlyTrunk { - size_t m_Size; - size_t m_Allocated; - _FX_GrowOnlyTrunk* m_pNext; -}; -void CFX_GrowOnlyPool::FreeAll() -{ - _FX_GrowOnlyTrunk* pTrunk = (_FX_GrowOnlyTrunk*)m_pFirstTrunk; - while (pTrunk) { - _FX_GrowOnlyTrunk* pNext = pTrunk->m_pNext; - FX_Free(pTrunk); - pTrunk = pNext; - } - m_pFirstTrunk = NULL; -} -void* CFX_GrowOnlyPool::Alloc(size_t size) -{ - size = (size + 3) / 4 * 4; - _FX_GrowOnlyTrunk* pTrunk = (_FX_GrowOnlyTrunk*)m_pFirstTrunk; - while (pTrunk) { - if (pTrunk->m_Size - pTrunk->m_Allocated >= size) { - void* p = (FX_LPBYTE)(pTrunk + 1) + pTrunk->m_Allocated; - pTrunk->m_Allocated += size; - return p; - } - pTrunk = pTrunk->m_pNext; - } - size_t alloc_size = size > m_TrunkSize ? size : m_TrunkSize; - pTrunk = (_FX_GrowOnlyTrunk*)FX_Alloc(FX_BYTE, sizeof(_FX_GrowOnlyTrunk) + alloc_size); - pTrunk->m_Size = alloc_size; - pTrunk->m_Allocated = size; - pTrunk->m_pNext = (_FX_GrowOnlyTrunk*)m_pFirstTrunk; - m_pFirstTrunk = pTrunk; - return pTrunk + 1; -} + +} // extern "C" -- cgit v1.2.3