include/svl/poolitem.hxx | 19 ++++++++------- sfx2/source/control/itemdel.cxx | 2 - svl/source/items/itempool.cxx | 12 ++++----- svl/source/items/poolio.cxx | 50 +++++++++++++++++++++++----------------- svl/source/items/poolitem.cxx | 4 +-- 5 files changed, 48 insertions(+), 39 deletions(-)
New commits: commit a49748caf2bc3d236862eef5d26383212d35e648 Author: Jochen Nitschke <j.nitschke+loger...@ok.de> Date: Thu Sep 22 16:02:24 2016 +0200 convert SfxItemKind to scoped enum reduced size because it is stored in widely used SfxPoolItem. converted 'if' chains to 'switch case' Change-Id: Id9b5e375b681c88e8c91c561abd1a50610aa4815 Reviewed-on: https://gerrit.libreoffice.org/29186 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/svl/poolitem.hxx b/include/svl/poolitem.hxx index b758849..cf7c96e 100644 --- a/include/svl/poolitem.hxx +++ b/include/svl/poolitem.hxx @@ -34,11 +34,12 @@ class IntlWrapper; class SvStream; -enum SfxItemKind { - SFX_ITEMS_NONE, - SFX_ITEMS_DELETEONIDLE, - SFX_ITEMS_STATICDEFAULT, - SFX_ITEMS_POOLDEFAULT +enum class SfxItemKind : sal_Int8 +{ + NONE, + DeleteOnIdle, + StaticDefault, + PoolDefault }; #define SFX_ITEMS_OLD_MAXREF 0xffef @@ -180,7 +181,7 @@ private: inline void SfxPoolItem::SetRefCount( sal_uLong n ) { m_nRefCount = n; - m_nKind = SFX_ITEMS_NONE; + m_nKind = SfxItemKind::NONE; } inline void SfxPoolItem::SetKind( SfxItemKind n ) @@ -206,17 +207,17 @@ inline sal_uLong SfxPoolItem::ReleaseRef( sal_uLong n ) const inline bool IsPoolDefaultItem(const SfxPoolItem *pItem ) { - return pItem && pItem->GetKind() == SFX_ITEMS_POOLDEFAULT; + return pItem && pItem->GetKind() == SfxItemKind::PoolDefault; } inline bool IsStaticDefaultItem(const SfxPoolItem *pItem ) { - return pItem && pItem->GetKind() == SFX_ITEMS_STATICDEFAULT; + return pItem && pItem->GetKind() == SfxItemKind::StaticDefault; } inline bool IsDefaultItem( const SfxPoolItem *pItem ) { - return pItem && (pItem->GetKind() == SFX_ITEMS_STATICDEFAULT || pItem->GetKind() == SFX_ITEMS_POOLDEFAULT); + return pItem && (pItem->GetKind() == SfxItemKind::StaticDefault || pItem->GetKind() == SfxItemKind::PoolDefault); } inline bool IsPooledItem( const SfxPoolItem *pItem ) diff --git a/sfx2/source/control/itemdel.cxx b/sfx2/source/control/itemdel.cxx index 1ac8ab8..096ab37 100644 --- a/sfx2/source/control/itemdel.cxx +++ b/sfx2/source/control/itemdel.cxx @@ -48,7 +48,7 @@ SfxItemDisruptor_Impl::SfxItemDisruptor_Impl(SfxPoolItem *const pItemToDisrupt) m_Idle.SetPriority(SchedulerPriority::DEFAULT_IDLE); DBG_ASSERT( 0 == pItem->GetRefCount(), "disrupting pooled item" ); - pItem->SetKind( SFX_ITEMS_DELETEONIDLE ); + pItem->SetKind(SfxItemKind::DeleteOnIdle); } void SfxItemDisruptor_Impl::LaunchDeleteOnIdle() diff --git a/svl/source/items/itempool.cxx b/svl/source/items/itempool.cxx index 330d2f7..6f4a6f2 100644 --- a/svl/source/items/itempool.cxx +++ b/svl/source/items/itempool.cxx @@ -228,7 +228,7 @@ SfxItemPool::SfxItemPool for ( sal_uInt16 n = 0; n <= pImpl->mnEnd - pImpl->mnStart; ++n ) { (*( ppDefaults + n )) = (*( rPool.pImpl->ppStaticDefaults + n ))->Clone(this); - (*( ppDefaults + n ))->SetKind( SFX_ITEMS_STATICDEFAULT ); + (*( ppDefaults + n ))->SetKind(SfxItemKind::StaticDefault); } SetDefaults( ppDefaults ); @@ -241,7 +241,7 @@ SfxItemPool::SfxItemPool if (rPool.pImpl->maPoolDefaults[n]) { pImpl->maPoolDefaults[n] = rPool.pImpl->maPoolDefaults[n]->Clone(this); //resets kind - pImpl->maPoolDefaults[n]->SetKind(SFX_ITEMS_POOLDEFAULT); + pImpl->maPoolDefaults[n]->SetKind(SfxItemKind::PoolDefault); } // Copy Version map @@ -263,7 +263,7 @@ void SfxItemPool::SetDefaults( SfxPoolItem **pDefaults ) DBG_ASSERT( !pImpl->ppStaticDefaults, "already have Defaults" ); pImpl->ppStaticDefaults = pDefaults; - //! if ( (*ppStaticDefaults)->GetKind() != SFX_ITEMS_STATICDEFAULT ) + //! if ((*ppStaticDefaults)->GetKind() != SfxItemKind::StaticDefault) //! FIXME: Probably doesn't work with SetItems at the end { DBG_ASSERT( (*pImpl->ppStaticDefaults)->GetRefCount() == 0 || @@ -273,7 +273,7 @@ void SfxItemPool::SetDefaults( SfxPoolItem **pDefaults ) { assert(((*(pImpl->ppStaticDefaults + n))->Which() == n + pImpl->mnStart) && "static defaults not sorted" ); - (*( pImpl->ppStaticDefaults + n ))->SetKind( SFX_ITEMS_STATICDEFAULT ); + (*( pImpl->ppStaticDefaults + n ))->SetKind(SfxItemKind::StaticDefault); DBG_ASSERT( !(pImpl->maPoolItems[n]), "defaults with setitems with items?!" ); } } @@ -568,7 +568,7 @@ void SfxItemPool::SetPoolDefaultItem(const SfxPoolItem &rItem) auto& rOldDefault = pImpl->maPoolDefaults[GetIndex_Impl(rItem.Which())]; SfxPoolItem *pNewDefault = rItem.Clone(this); - pNewDefault->SetKind(SFX_ITEMS_POOLDEFAULT); + pNewDefault->SetKind(SfxItemKind::PoolDefault); if (rOldDefault) { rOldDefault->SetRefCount(0); @@ -627,7 +627,7 @@ const SfxPoolItem& SfxItemPool::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich if (bSID) { assert((rItem.Which() != nWhich || - !IsDefaultItem(&rItem) || rItem.GetKind() == SFX_ITEMS_DELETEONIDLE) + !IsDefaultItem(&rItem) || rItem.GetKind() == SfxItemKind::DeleteOnIdle) && "a non Pool Item is Default?!"); SfxPoolItem *pPoolItem = rItem.Clone(pImpl->mpMaster); pPoolItem->SetWhich(nWhich); diff --git a/svl/source/items/poolio.cxx b/svl/source/items/poolio.cxx index 0fa4263..ec23690 100644 --- a/svl/source/items/poolio.cxx +++ b/svl/source/items/poolio.cxx @@ -41,32 +41,40 @@ const SfxItemPool* SfxItemPool::GetStoringPool() return pStoringPool_; } -static sal_uInt16 convertSfxItemKindToUInt16(SfxItemKind x) +static sal_uInt16 convertSfxItemKindToUInt16(SfxItemKind eKind) { - if ( x == SFX_ITEMS_NONE ) + switch (eKind) + { + case SfxItemKind::NONE: return 0; - if ( x == SFX_ITEMS_DELETEONIDLE ) + case SfxItemKind::DeleteOnIdle: return 0xfffd; - if ( x == SFX_ITEMS_STATICDEFAULT ) + case SfxItemKind::StaticDefault: return 0xfffe; - if ( x == SFX_ITEMS_POOLDEFAULT ) + case SfxItemKind::PoolDefault: return 0xffff; - assert(false); - abort(); + default: + assert("unknown SfxItemKind"); + return 0; + } } -static SfxItemKind convertUInt16ToSfxItemKind(sal_uInt16 x) +static SfxItemKind convertUInt16ToSfxItemKind(sal_uInt16 nRefCnt) { - if ( x == 0 ) - return SFX_ITEMS_NONE; - if ( x == 0xfffd ) - return SFX_ITEMS_DELETEONIDLE; - if ( x == 0xfffe ) - return SFX_ITEMS_STATICDEFAULT; - if ( x == 0xffff ) - return SFX_ITEMS_POOLDEFAULT; - assert(false); - abort(); + switch (nRefCnt) + { + case 0: + return SfxItemKind::NONE; + case 0xfffd: + return SfxItemKind::DeleteOnIdle; + case 0xfffe: + return SfxItemKind::StaticDefault; + case 0xffff: + return SfxItemKind::PoolDefault; + default: + assert(false); + abort(); + } } @@ -688,7 +696,7 @@ SvStream &SfxItemPool::Load(SvStream &rStream) SfxPoolItem *pItem = ( *( pImpl->ppStaticDefaults + GetIndex_Impl(nWhich) ) ) ->Create( rStream, nVersion ); - pItem->SetKind( SFX_ITEMS_POOLDEFAULT ); + pItem->SetKind( SfxItemKind::PoolDefault ); pImpl->maPoolDefaults[GetIndex_Impl(nWhich)] = pItem; } } @@ -851,8 +859,8 @@ const SfxPoolItem* SfxItemPool::LoadSurrogate * Saves a surrogate for '*pItem' in 'rStream' * * @returns sal_True: a real surrogates has been saved - * SFX_ITEMS_NULL for 'pItem==0', SFX_ITEMS_STATICDEFAULT - * and SFX_ITEMS_POOLDEFAULT are 'real' surrogates + * SFX_ITEMS_NULL for 'pItem==0', SfxItemKind::StaticDefault + * and SfxItemKind::PoolDefault are 'real' surrogates * * @returns sal_False: a dummy surrogate (SFX_ITEMS_DIRECT) has been saved; * the actual Item needs to be saved right after it on diff --git a/svl/source/items/poolitem.cxx b/svl/source/items/poolitem.cxx index f11a290..d6bfea4 100644 --- a/svl/source/items/poolitem.cxx +++ b/svl/source/items/poolitem.cxx @@ -38,7 +38,7 @@ const char* pw5 = "Wow! 10.000.000 items!"; SfxPoolItem::SfxPoolItem(sal_uInt16 const nWhich) : m_nRefCount(0) , m_nWhich(nWhich) - , m_nKind(SFX_ITEMS_NONE) + , m_nKind(SfxItemKind::NONE) { DBG_ASSERT(nWhich <= SHRT_MAX, "invalid WhichId"); #if OSL_DEBUG_LEVEL > 0 @@ -75,7 +75,7 @@ SfxPoolItem::SfxPoolItem(sal_uInt16 const nWhich) SfxPoolItem::SfxPoolItem( const SfxPoolItem& rCpy ) : m_nRefCount(0) // don't copy that , m_nWhich(rCpy.m_nWhich) - , m_nKind( SFX_ITEMS_NONE ) + , m_nKind(SfxItemKind::NONE) { #if OSL_DEBUG_LEVEL > 0 ++nItemCount; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits