store/source/lockbyte.cxx | 35 ++++----- store/source/lockbyte.hxx | 12 ++- store/source/storbase.cxx | 33 -------- store/source/storbase.hxx | 176 ++++++---------------------------------------- store/source/storcach.cxx | 17 ++-- store/source/storcach.hxx | 10 +- store/source/stordata.hxx | 20 ++--- store/source/stortree.cxx | 14 ++- store/source/stortree.hxx | 10 +- 9 files changed, 92 insertions(+), 235 deletions(-)
New commits: commit 98323f936ba454f974d168e79f2187a8d3324ef0 Author: Stephan Bergmann <sberg...@redhat.com> Date: Fri Sep 30 11:04:13 2016 +0200 cid#1371195, cide#1371212: Replace PageHolder with shared_ptr ...removing the need for SharedCount, too Change-Id: I20c724c940c571aef1c12453da30c3e9fbb46466 diff --git a/store/source/lockbyte.cxx b/store/source/lockbyte.cxx index 73ad47f..b0b2b52 100644 --- a/store/source/lockbyte.cxx +++ b/store/source/lockbyte.cxx @@ -30,6 +30,7 @@ #include "object.hxx" #include "storbase.hxx" +#include <memory> #include <string.h> using namespace store; @@ -46,7 +47,7 @@ storeError ILockBytes::initialize (rtl::Reference< PageData::Allocator > & rxAll return initialize_Impl (rxAllocator, nPageSize); } -storeError ILockBytes::readPageAt (PageHolder & rPage, sal_uInt32 nOffset) +storeError ILockBytes::readPageAt (std::shared_ptr<PageData> & rPage, sal_uInt32 nOffset) { OSL_PRECOND(!(nOffset == STORE_PAGE_NULL), "store::ILockBytes::readPageAt(): invalid Offset"); if (nOffset == STORE_PAGE_NULL) @@ -55,7 +56,7 @@ storeError ILockBytes::readPageAt (PageHolder & rPage, sal_uInt32 nOffset) return readPageAt_Impl (rPage, nOffset); } -storeError ILockBytes::writePageAt (PageHolder const & rPage, sal_uInt32 nOffset) +storeError ILockBytes::writePageAt (std::shared_ptr<PageData> const & rPage, sal_uInt32 nOffset) { // [SECURITY:ValInput] PageData const * pagedata = rPage.get(); @@ -291,8 +292,8 @@ class FileLockBytes : */ virtual storeError initialize_Impl (rtl::Reference< PageData::Allocator > & rxAllocator, sal_uInt16 nPageSize) override; - virtual storeError readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOffset) override; - virtual storeError writePageAt_Impl (PageHolder const & rPage, sal_uInt32 nOffset) override; + virtual storeError readPageAt_Impl (std::shared_ptr<PageData> & rPage, sal_uInt32 nOffset) override; + virtual storeError writePageAt_Impl (std::shared_ptr<PageData> const & rPage, sal_uInt32 nOffset) override; virtual storeError readAt_Impl (sal_uInt32 nOffset, void * pBuffer, sal_uInt32 nBytes) override; virtual storeError writeAt_Impl (sal_uInt32 nOffset, void const * pBuffer, sal_uInt32 nBytes) override; @@ -360,11 +361,11 @@ storeError FileLockBytes::initialize_Impl (rtl::Reference< PageData::Allocator > return store_E_None; } -storeError FileLockBytes::readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOffset) +storeError FileLockBytes::readPageAt_Impl (std::shared_ptr<PageData> & rPage, sal_uInt32 nOffset) { if (m_xAllocator.is()) { - PageHolder page (m_xAllocator->construct<PageData>(), m_xAllocator); + std::shared_ptr<PageData> page (m_xAllocator->construct<PageData>(), PageData::Deallocate(m_xAllocator)); page.swap (rPage); } @@ -377,7 +378,7 @@ storeError FileLockBytes::readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOffse return readAt_Impl (nOffset, pagedata, pagedata->size()); } -storeError FileLockBytes::writePageAt_Impl (PageHolder const & rPage, sal_uInt32 nOffset) +storeError FileLockBytes::writePageAt_Impl (std::shared_ptr<PageData> const & rPage, sal_uInt32 nOffset) { PageData const * pagedata = rPage.get(); OSL_PRECOND(pagedata != nullptr, "contract violation"); @@ -519,8 +520,8 @@ class MappedLockBytes : */ virtual storeError initialize_Impl (rtl::Reference< PageData::Allocator > & rxAllocator, sal_uInt16 nPageSize) override; - virtual storeError readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOffset) override; - virtual storeError writePageAt_Impl (PageHolder const & rPage, sal_uInt32 nOffset) override; + virtual storeError readPageAt_Impl (std::shared_ptr<PageData> & rPage, sal_uInt32 nOffset) override; + virtual storeError writePageAt_Impl (std::shared_ptr<PageData> const & rPage, sal_uInt32 nOffset) override; virtual storeError readAt_Impl (sal_uInt32 nOffset, void * pBuffer, sal_uInt32 nBytes) override; virtual storeError writeAt_Impl (sal_uInt32 nOffset, const void * pBuffer, sal_uInt32 nBytes) override; @@ -579,7 +580,7 @@ storeError MappedLockBytes::initialize_Impl (rtl::Reference< PageData::Allocator return store_E_None; } -storeError MappedLockBytes::readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOffset) +storeError MappedLockBytes::readPageAt_Impl (std::shared_ptr<PageData> & rPage, sal_uInt32 nOffset) { sal_uInt8 * src_lo = m_pData + nOffset; if ((m_pData > src_lo) || (src_lo >= m_pData + m_nSize)) @@ -589,13 +590,13 @@ storeError MappedLockBytes::readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOff if ((m_pData > src_hi) || (src_hi > m_pData + m_nSize)) return store_E_CantRead; - PageHolder page (reinterpret_cast< PageData* >(src_lo), static_cast< PageData::Allocator* >(this)); + std::shared_ptr<PageData> page (reinterpret_cast< PageData* >(src_lo), PageData::Deallocate(static_cast< PageData::Allocator* >(this))); page.swap (rPage); return store_E_None; } -storeError MappedLockBytes::writePageAt_Impl (PageHolder const & /*rPage*/, sal_uInt32 /*nOffset*/) +storeError MappedLockBytes::writePageAt_Impl (std::shared_ptr<PageData> const & /*rPage*/, sal_uInt32 /*nOffset*/) { return store_E_AccessViolation; } @@ -657,8 +658,8 @@ class MemoryLockBytes : */ virtual storeError initialize_Impl (rtl::Reference< PageData::Allocator > & rxAllocator, sal_uInt16 nPageSize) override; - virtual storeError readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOffset) override; - virtual storeError writePageAt_Impl (PageHolder const & rPage, sal_uInt32 nOffset) override; + virtual storeError readPageAt_Impl (std::shared_ptr<PageData> & rPage, sal_uInt32 nOffset) override; + virtual storeError writePageAt_Impl (std::shared_ptr<PageData> const & rPage, sal_uInt32 nOffset) override; virtual storeError readAt_Impl (sal_uInt32 nOffset, void * pBuffer, sal_uInt32 nBytes) override; virtual storeError writeAt_Impl (sal_uInt32 nOffset, const void * pBuffer, sal_uInt32 nBytes) override; @@ -704,11 +705,11 @@ storeError MemoryLockBytes::initialize_Impl (rtl::Reference< PageData::Allocator return result; } -storeError MemoryLockBytes::readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOffset) +storeError MemoryLockBytes::readPageAt_Impl (std::shared_ptr<PageData> & rPage, sal_uInt32 nOffset) { if (m_xAllocator.is()) { - PageHolder page (m_xAllocator->construct<PageData>(), m_xAllocator); + std::shared_ptr<PageData> page (m_xAllocator->construct<PageData>(), PageData::Deallocate(m_xAllocator)); page.swap (rPage); } @@ -721,7 +722,7 @@ storeError MemoryLockBytes::readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOff return readAt_Impl (nOffset, pagedata, pagedata->size()); } -storeError MemoryLockBytes::writePageAt_Impl (PageHolder const & rPage, sal_uInt32 nOffset) +storeError MemoryLockBytes::writePageAt_Impl (std::shared_ptr<PageData> const & rPage, sal_uInt32 nOffset) { PageData const * pagedata = rPage.get(); OSL_PRECOND(!(pagedata == nullptr), "contract violation"); diff --git a/store/source/lockbyte.hxx b/store/source/lockbyte.hxx index 1a864ad..b92e8b47 100644 --- a/store/source/lockbyte.hxx +++ b/store/source/lockbyte.hxx @@ -20,6 +20,10 @@ #ifndef INCLUDED_STORE_SOURCE_LOCKBYTE_HXX #define INCLUDED_STORE_SOURCE_LOCKBYTE_HXX +#include <sal/config.h> + +#include <memory> + #include "sal/types.h" #include "rtl/ref.hxx" @@ -53,7 +57,7 @@ public: @param nOffset [in] */ storeError readPageAt ( - PageHolder & rPage, + std::shared_ptr<PageData> & rPage, sal_uInt32 nOffset); /** @@ -61,7 +65,7 @@ public: @param nOffset [in] */ storeError writePageAt ( - PageHolder const & rPage, + std::shared_ptr<PageData> const & rPage, sal_uInt32 nOffset); /** @@ -114,11 +118,11 @@ private: sal_uInt16 nPageSize) = 0; virtual storeError readPageAt_Impl ( - PageHolder & rPage, + std::shared_ptr<PageData> & rPage, sal_uInt32 nOffset) = 0; virtual storeError writePageAt_Impl ( - PageHolder const & rPage, + std::shared_ptr<PageData> const & rPage, sal_uInt32 nOffset) = 0; virtual storeError readAt_Impl ( diff --git a/store/source/storbase.hxx b/store/source/storbase.hxx index 49ff131..0b16fae 100644 --- a/store/source/storbase.hxx +++ b/store/source/storbase.hxx @@ -34,6 +34,7 @@ #include "store/types.h" +#include <memory> #include <stddef.h> #include <string.h> #include <utility> @@ -77,52 +78,6 @@ inline sal_uInt32 ntohl (sal_uInt32 n) { return n; } /*======================================================================== * - * SharedCount. - * - *======================================================================*/ -class SharedCount -{ - long * m_pCount; - -public: - SharedCount() - : m_pCount(new long) - { - (*m_pCount) = 1; - } - - ~SharedCount() - { - long new_count = --(*m_pCount); - if (new_count == 0) - delete m_pCount; - } - - void swap (SharedCount & rhs) // nothrow - { - std::swap(m_pCount, rhs.m_pCount); - } - - SharedCount (SharedCount const & rhs) // nothrow - : m_pCount (rhs.m_pCount) - { - ++(*m_pCount); - } - SharedCount & operator= (SharedCount const & rhs) // nothrow - { - SharedCount tmp(rhs); - swap(tmp); - return *this; - } - - bool operator== (long count) const - { - return *m_pCount == count; - } -}; - -/*======================================================================== - * * OStorePageGuard. * *======================================================================*/ @@ -416,6 +371,17 @@ struct PageData virtual void deallocate_Impl (void * pPage) = 0; }; + class Deallocate { + public: + explicit Deallocate(rtl::Reference<Allocator> const & allocator): + allocator_(allocator) {}; + + void operator ()(void * page) const { allocator_->deallocate(page); } + + private: + rtl::Reference<Allocator> allocator_; + }; + static void* operator new (size_t, void * p) { return p; } static void operator delete (void * , void *) {} @@ -479,73 +445,6 @@ struct PageData /*======================================================================== * - * PageHolder. - * - *======================================================================*/ -class PageHolder -{ - SharedCount m_refcount; - PageData * m_pagedata; - - typedef rtl::Reference< PageData::Allocator > allocator_type; - allocator_type m_allocator; - -public: - explicit PageHolder (PageData * pagedata = nullptr, allocator_type const & allocator = allocator_type()) - : m_refcount (), - m_pagedata (pagedata), - m_allocator(allocator) - { - OSL_ENSURE((m_pagedata == nullptr) || m_allocator.is(), "store::PageHolder::ctor(): pagedata w/o allocator."); - } - - ~PageHolder() - { - if ((m_refcount == 1) && (m_pagedata != nullptr)) - { - // free pagedata. - OSL_ENSURE(m_allocator.is(), "store::PageHolder::dtor(): pagedata w/o allocator."); - m_allocator->deallocate (m_pagedata); - } - } - - void swap (PageHolder & rhs) // nothrow - { - m_refcount.swap(rhs.m_refcount); - std::swap(m_pagedata, rhs.m_pagedata); - std::swap(m_allocator, rhs.m_allocator); - } - - PageHolder (PageHolder const & rhs) // nothrow - : m_refcount (rhs.m_refcount), - m_pagedata (rhs.m_pagedata), - m_allocator(rhs.m_allocator) - {} - - PageHolder & operator= (PageHolder const & rhs) // nothrow - { - PageHolder tmp (rhs); - swap(tmp); - return *this; - } - - PageData * get() { return m_pagedata; } - PageData const * get() const { return m_pagedata; } - - PageData * operator->() - { - OSL_PRECOND(m_pagedata != nullptr, "store::PageHolder::operator->(): Null pointer"); - return m_pagedata; - } - PageData const * operator->() const - { - OSL_PRECOND(m_pagedata != nullptr, "store::PageHolder::operator->(): Null pointer"); - return m_pagedata; - } -}; - -/*======================================================================== - * * PageHolderObject. * *======================================================================*/ @@ -554,7 +453,7 @@ class PageHolderObject { /** Representation. */ - PageHolder m_xPage; + std::shared_ptr<PageData> m_xPage; /** Checked cast. */ @@ -581,13 +480,13 @@ public: { if ((m_xPage.get() == 0) && rxAllocator.is()) { - PageHolder tmp (rxAllocator->construct<T>(), rxAllocator); + std::shared_ptr<PageData> tmp (rxAllocator->construct<T>(), PageData::Deallocate(rxAllocator)); m_xPage.swap (tmp); } return (m_xPage.get() != 0); } - explicit PageHolderObject (PageHolder const & rxPage = PageHolder()) + explicit PageHolderObject (std::shared_ptr<PageData> const & rxPage = std::shared_ptr<PageData>()) : m_xPage (rxPage) {} @@ -612,8 +511,8 @@ public: return (m_xPage.get() != 0); } - PageHolder & get() { return m_xPage; } - PageHolder const & get() const { return m_xPage; } + std::shared_ptr<PageData> & get() { return m_xPage; } + std::shared_ptr<PageData> const & get() const { return m_xPage; } T * operator->() { @@ -641,7 +540,7 @@ public: return (*pImpl); } - static storeError guard (PageHolder & rxPage, sal_uInt32 nAddr) + static storeError guard (std::shared_ptr<PageData> & rxPage, sal_uInt32 nAddr) { PageData * pHead = rxPage.get(); if (!pHead) @@ -654,7 +553,7 @@ public: return store_E_None; } - static storeError verify (PageHolder const & rxPage, sal_uInt32 nAddr) + static storeError verify (std::shared_ptr<PageData> const & rxPage, sal_uInt32 nAddr) { PageData const * pHead = rxPage.get(); if (!pHead) @@ -704,12 +603,12 @@ public: protected: /** Representation. */ - PageHolder m_xPage; + std::shared_ptr<PageData> m_xPage; bool m_bDirty; /** Construction. */ - explicit OStorePageObject (PageHolder const & rxPage = PageHolder()) + explicit OStorePageObject (std::shared_ptr<PageData> const & rxPage = std::shared_ptr<PageData>()) : m_xPage (rxPage), m_bDirty (false) {} @@ -730,7 +629,7 @@ public: if (!rxAllocator.is()) return store_E_InvalidAccess; - PageHolder tmp (rxAllocator->construct<U>(), rxAllocator); + std::shared_ptr<PageData> tmp (rxAllocator->construct<U>(), PageData::Deallocate(rxAllocator)); if (!tmp.get()) return store_E_OutOfMemory; @@ -738,7 +637,7 @@ public: return store_E_None; } - PageHolder & get() { return m_xPage; } + std::shared_ptr<PageData> & get() { return m_xPage; } virtual storeError guard (sal_uInt32 nAddr) = 0; virtual storeError verify (sal_uInt32 nAddr) const = 0; diff --git a/store/source/storcach.cxx b/store/source/storcach.cxx index a37a017..8825d69 100644 --- a/store/source/storcach.cxx +++ b/store/source/storcach.cxx @@ -31,6 +31,7 @@ #include "object.hxx" #include "storbase.hxx" +#include <memory> #include <stddef.h> using namespace store; @@ -41,7 +42,7 @@ namespace store { struct Entry { // Representation - PageHolder m_xPage; + std::shared_ptr<PageData> m_xPage; sal_uInt32 m_nOffset; Entry * m_pNext; @@ -50,7 +51,7 @@ struct Entry static void operator delete (void *, void *) {} // Construction - explicit Entry (PageHolder const & rxPage = PageHolder(), sal_uInt32 nOffset = STORE_PAGE_NULL) + explicit Entry (std::shared_ptr<PageData> const & rxPage = std::shared_ptr<PageData>(), sal_uInt32 nOffset = STORE_PAGE_NULL) : m_xPage(rxPage), m_nOffset(nOffset), m_pNext(nullptr) {} @@ -70,7 +71,7 @@ class EntryCache public: static EntryCache & get(); - Entry * create (PageHolder const & rxPage, sal_uInt32 nOffset); + Entry * create (std::shared_ptr<PageData> const & rxPage, sal_uInt32 nOffset); void destroy (Entry * entry); @@ -109,7 +110,7 @@ EntryCache::~EntryCache() m_entry_cache = nullptr; } -Entry * EntryCache::create (PageHolder const & rxPage, sal_uInt32 nOffset) +Entry * EntryCache::create (std::shared_ptr<PageData> const & rxPage, sal_uInt32 nOffset) { void * pAddr = rtl_cache_alloc (m_entry_cache); if (pAddr != nullptr) @@ -285,7 +286,7 @@ Entry * PageCache::lookup_Impl (Entry * entry, sal_uInt32 nOffset) return entry; } -storeError PageCache::lookupPageAt (PageHolder & rxPage, sal_uInt32 nOffset) +storeError PageCache::lookupPageAt (std::shared_ptr<PageData> & rxPage, sal_uInt32 nOffset) { OSL_PRECOND(!(nOffset == STORE_PAGE_NULL), "store::PageCache::lookupPageAt(): invalid Offset"); if (nOffset == STORE_PAGE_NULL) @@ -308,7 +309,7 @@ storeError PageCache::lookupPageAt (PageHolder & rxPage, sal_uInt32 nOffset) return store_E_NotExists; } -storeError PageCache::insertPageAt (PageHolder const & rxPage, sal_uInt32 nOffset) +storeError PageCache::insertPageAt (std::shared_ptr<PageData> const & rxPage, sal_uInt32 nOffset) { // [SECURITY:ValInput] PageData const * pagedata = rxPage.get(); @@ -340,7 +341,7 @@ storeError PageCache::insertPageAt (PageHolder const & rxPage, sal_uInt32 nOffse return store_E_OutOfMemory; } -storeError PageCache::updatePageAt (PageHolder const & rxPage, sal_uInt32 nOffset) +storeError PageCache::updatePageAt (std::shared_ptr<PageData> const & rxPage, sal_uInt32 nOffset) { // [SECURITY:ValInput] PageData const * pagedata = rxPage.get(); diff --git a/store/source/storcach.hxx b/store/source/storcach.hxx index 5125160..3f78172 100644 --- a/store/source/storcach.hxx +++ b/store/source/storcach.hxx @@ -20,6 +20,10 @@ #ifndef INCLUDED_STORE_SOURCE_STORCACH_HXX #define INCLUDED_STORE_SOURCE_STORCACH_HXX +#include <sal/config.h> + +#include <memory> + #include "sal/types.h" #include "rtl/ref.hxx" @@ -77,19 +81,19 @@ public: /** load. */ storeError lookupPageAt ( - PageHolder & rxPage, + std::shared_ptr<PageData> & rxPage, sal_uInt32 nOffset); /** insert. */ storeError insertPageAt ( - PageHolder const & rxPage, + std::shared_ptr<PageData> const & rxPage, sal_uInt32 nOffset); /** update, or insert. */ storeError updatePageAt ( - PageHolder const & rxPage, + std::shared_ptr<PageData> const & rxPage, sal_uInt32 nOffset); /** remove (invalidate). diff --git a/store/source/stordata.hxx b/store/source/stordata.hxx index 2c3a28b..02bddf0 100644 --- a/store/source/stordata.hxx +++ b/store/source/stordata.hxx @@ -22,6 +22,8 @@ #include "sal/config.h" +#include <memory> + #include "sal/types.h" #include "sal/macros.h" #include "rtl/string.h" @@ -106,7 +108,7 @@ class OStoreDataPageObject : public store::OStorePageObject public: /** Construction. */ - explicit OStoreDataPageObject (PageHolder const & rxPage = PageHolder()) + explicit OStoreDataPageObject (std::shared_ptr<PageData> const & rxPage = std::shared_ptr<PageData>()) : OStorePageObject (rxPage) {} @@ -216,7 +218,7 @@ class OStoreIndirectionPageObject : public store::OStorePageObject public: /** Construction. */ - explicit OStoreIndirectionPageObject (PageHolder const & rxPage = PageHolder()) + explicit OStoreIndirectionPageObject (std::shared_ptr<PageData> const & rxPage = std::shared_ptr<PageData>()) : OStorePageObject (rxPage) {} @@ -641,7 +643,7 @@ class OStoreDirectoryPageObject : public store::OStorePageObject public: /** Construction. */ - explicit OStoreDirectoryPageObject (PageHolder const & rxPage = PageHolder()) + explicit OStoreDirectoryPageObject (std::shared_ptr<PageData> const & rxPage = std::shared_ptr<PageData>()) : OStorePageObject (rxPage) {} diff --git a/store/source/stortree.cxx b/store/source/stortree.cxx index fec3138..1b5e227 100644 --- a/store/source/stortree.cxx +++ b/store/source/stortree.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <memory> + #include "stortree.hxx" #include "sal/types.h" @@ -358,7 +362,7 @@ storeError OStoreBTreeRootObject::change ( // Change root. rxPageL.swap (xPage); { - PageHolder tmp (xPage.get()); + std::shared_ptr<PageData> tmp (xPage.get()); tmp.swap (m_xPage); } @@ -381,7 +385,7 @@ storeError OStoreBTreeRootObject::find_lookup ( // Init node w/ root page. testInvariant("OStoreBTreeRootObject::find_lookup(): enter"); { - PageHolder tmp (m_xPage); + std::shared_ptr<PageData> tmp (m_xPage); tmp.swap (rNode.get()); } @@ -466,7 +470,7 @@ storeError OStoreBTreeRootObject::find_insert ( // Init node w/ root page. { - PageHolder tmp (m_xPage); + std::shared_ptr<PageData> tmp (m_xPage); tmp.swap (rNode.get()); } @@ -515,7 +519,7 @@ storeError OStoreBTreeRootObject::find_insert ( } // Let next page be current. - PageHolder tmp (aNext.get()); + std::shared_ptr<PageData> tmp (aNext.get()); tmp.swap (rNode.get()); } diff --git a/store/source/stortree.hxx b/store/source/stortree.hxx index f5aea52..114377a 100644 --- a/store/source/stortree.hxx +++ b/store/source/stortree.hxx @@ -22,6 +22,8 @@ #include "sal/config.h" +#include <memory> + #include "sal/types.h" #include "store/types.h" @@ -232,7 +234,7 @@ class OStoreBTreeNodeObject : public store::OStorePageObject public: /** Construction. */ - explicit OStoreBTreeNodeObject (PageHolder const & rxPage = PageHolder()) + explicit OStoreBTreeNodeObject (std::shared_ptr<PageData> const & rxPage = std::shared_ptr<PageData>()) : OStorePageObject (rxPage) {} @@ -273,7 +275,7 @@ class OStoreBTreeRootObject : public store::OStoreBTreeNodeObject public: /** Construction. */ - explicit OStoreBTreeRootObject (PageHolder const & rxPage = PageHolder()) + explicit OStoreBTreeRootObject (std::shared_ptr<PageData> const & rxPage = std::shared_ptr<PageData>()) : OStoreBTreeNodeObject (rxPage) {} commit 904959b85853be0a79c757f9df92e1a9b7e0c01c Author: Stephan Bergmann <sberg...@redhat.com> Date: Fri Sep 30 10:38:20 2016 +0200 Remove OStorePageData typedef Change-Id: I9f4e8fa41a59325fe7036acb66d045a833294bd6 diff --git a/store/source/storbase.hxx b/store/source/storbase.hxx index 7d006c6..49ff131 100644 --- a/store/source/storbase.hxx +++ b/store/source/storbase.hxx @@ -331,7 +331,6 @@ struct OStorePageLink * PageData. * *======================================================================*/ -typedef struct PageData OStorePageData; // backward compat. struct PageData { typedef OStorePageGuard G; @@ -678,7 +677,7 @@ class OStorePageBIOS; class OStorePageObject { - typedef OStorePageData page; + typedef PageData page; public: /** Allocation. diff --git a/store/source/storcach.cxx b/store/source/storcach.cxx index d8449be..a37a017 100644 --- a/store/source/storcach.cxx +++ b/store/source/storcach.cxx @@ -403,7 +403,7 @@ storeError PageCache::removePageAt (sal_uInt32 nOffset) * Old OStorePageCache implementation. * * (two-way association (sorted address array, LRU chain)). - * (external OStorePageData representation). + * (external PageData representation). * */ diff --git a/store/source/stordata.hxx b/store/source/stordata.hxx index c9946c2..2c3a28b 100644 --- a/store/source/stordata.hxx +++ b/store/source/stordata.hxx @@ -39,9 +39,9 @@ namespace store *======================================================================*/ #define STORE_MAGIC_DATAPAGE sal_uInt32(0x94190310) -struct OStoreDataPageData : public store::OStorePageData +struct OStoreDataPageData : public store::PageData { - typedef OStorePageData base; + typedef PageData base; typedef OStoreDataPageData self; typedef OStorePageDescriptor D; @@ -123,9 +123,9 @@ public: *======================================================================*/ #define STORE_MAGIC_INDIRECTPAGE sal_uInt32(0x89191107) -struct OStoreIndirectionPageData : public store::OStorePageData +struct OStoreIndirectionPageData : public store::PageData { - typedef OStorePageData base; + typedef PageData base; typedef OStoreIndirectionPageData self; typedef OStorePageGuard G; @@ -519,9 +519,9 @@ struct OStoreDirectoryDataBlock *======================================================================*/ #define STORE_MAGIC_DIRECTORYPAGE sal_uInt32(0x62190120) -struct OStoreDirectoryPageData : public store::OStorePageData +struct OStoreDirectoryPageData : public store::PageData { - typedef OStorePageData base; + typedef PageData base; typedef OStoreDirectoryPageData self; typedef OStorePageDescriptor D; diff --git a/store/source/stortree.cxx b/store/source/stortree.cxx index d8d6d02..fec3138 100644 --- a/store/source/stortree.cxx +++ b/store/source/stortree.cxx @@ -39,7 +39,7 @@ using namespace store; * OStoreBTreeNodeData. */ OStoreBTreeNodeData::OStoreBTreeNodeData (sal_uInt16 nPageSize) - : OStorePageData (nPageSize) + : PageData (nPageSize) { base::m_aGuard.m_nMagic = store::htonl(self::theTypeId); base::m_aDescr.m_nUsed = store::htons(self::thePageSize); // usageCount(0) diff --git a/store/source/stortree.hxx b/store/source/stortree.hxx index 1146859..f5aea52 100644 --- a/store/source/stortree.hxx +++ b/store/source/stortree.hxx @@ -100,9 +100,9 @@ struct OStoreBTreeEntry *======================================================================*/ #define STORE_MAGIC_BTREENODE sal_uInt32(0x58190322) -struct OStoreBTreeNodeData : public store::OStorePageData +struct OStoreBTreeNodeData : public store::PageData { - typedef OStorePageData base; + typedef PageData base; typedef OStoreBTreeNodeData self; typedef OStorePageGuard G; commit ba09cda3ef52f58a1d5387ee33b30042baf2bf34 Author: Stephan Bergmann <sberg...@redhat.com> Date: Fri Sep 30 10:25:45 2016 +0200 Remove "#if 1 /* EXP */" ...whatever it was supposed to be good for Change-Id: I8f2a526aeaa484675e1bd6763fa692f8cbed2a51 diff --git a/store/source/storbase.hxx b/store/source/storbase.hxx index a4be847..7d006c6 100644 --- a/store/source/storbase.hxx +++ b/store/source/storbase.hxx @@ -613,10 +613,8 @@ public: return (m_xPage.get() != 0); } -#if 1 /* EXP */ PageHolder & get() { return m_xPage; } PageHolder const & get() const { return m_xPage; } -#endif /* EXP */ T * operator->() { commit 2950528c51b175ae704c674010d8538e3e83da08 Author: Stephan Bergmann <sberg...@redhat.com> Date: Fri Sep 30 10:18:19 2016 +0200 No need for rtl_cache_* here ...which shows that m_pCount will never be null Change-Id: I87c6e4bf5d258c59a8e91cd194c64b1ce85b4445 diff --git a/store/source/storbase.cxx b/store/source/storbase.cxx index bb2cf27..7e2a8cd 100644 --- a/store/source/storbase.cxx +++ b/store/source/storbase.cxx @@ -33,39 +33,6 @@ using namespace store; /*======================================================================== * - * SharedCount::Allocator. - * - *======================================================================*/ -SharedCount::Allocator & -SharedCount::Allocator::get() -{ - static Allocator g_aSharedCountAllocator; - return g_aSharedCountAllocator; -} - -SharedCount::Allocator::Allocator() -{ - m_cache = rtl_cache_create ( - "store_shared_count_cache", - sizeof(long), - 0, // objalign - nullptr, // constructor - nullptr, // destructor - nullptr, // reclaim - nullptr, // userarg - nullptr, // default source - 0 // flags - ); -} - -SharedCount::Allocator::~Allocator() -{ - rtl_cache_destroy (m_cache); - m_cache = nullptr; -} - -/*======================================================================== - * * PageData::Allocator_Impl (default allocator). * *======================================================================*/ diff --git a/store/source/storbase.hxx b/store/source/storbase.hxx index b861047..a4be847 100644 --- a/store/source/storbase.hxx +++ b/store/source/storbase.hxx @@ -84,42 +84,18 @@ class SharedCount { long * m_pCount; - class Allocator - { - rtl_cache_type * m_cache; - - public: - static Allocator & get(); - - long * alloc() - { - return static_cast<long*>(rtl_cache_alloc (m_cache)); - } - void free (long * pCount) - { - rtl_cache_free (m_cache, pCount); - } - - protected: - Allocator(); - ~Allocator(); - }; - public: SharedCount() - : m_pCount(Allocator::get().alloc()) + : m_pCount(new long) { - if (m_pCount != nullptr) (*m_pCount) = 1; + (*m_pCount) = 1; } ~SharedCount() { - if (m_pCount != nullptr) - { - long new_count = --(*m_pCount); - if (new_count == 0) - Allocator::get().free(m_pCount); - } + long new_count = --(*m_pCount); + if (new_count == 0) + delete m_pCount; } void swap (SharedCount & rhs) // nothrow @@ -130,7 +106,7 @@ public: SharedCount (SharedCount const & rhs) // nothrow : m_pCount (rhs.m_pCount) { - if (m_pCount != nullptr) ++(*m_pCount); + ++(*m_pCount); } SharedCount & operator= (SharedCount const & rhs) // nothrow { @@ -141,7 +117,7 @@ public: bool operator== (long count) const { - return (m_pCount != nullptr) && (*m_pCount == count); + return *m_pCount == count; } }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits