From 7281f4a73ec3679798a6271ab5a0ad839f278e37 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 11 Sep 2017 17:13:03 +0200 Subject: use std::unique_ptr in TItemInfo and inline the TItems typedef Change-Id: I0c50d12d53ce4b52c330cad8790a65065ebdd82e Reviewed-on: https://gerrit.libreoffice.org/42182 Reviewed-by: Noel Grandin Tested-by: Noel Grandin --- svl/source/config/itemholder2.cxx | 22 ++++++---------------- svl/source/config/itemholder2.hxx | 2 +- 2 files changed, 7 insertions(+), 17 deletions(-) (limited to 'svl/source/config') diff --git a/svl/source/config/itemholder2.cxx b/svl/source/config/itemholder2.cxx index 1511b47082a3..b809eba57b1d 100644 --- a/svl/source/config/itemholder2.cxx +++ b/svl/source/config/itemholder2.cxx @@ -79,12 +79,8 @@ void ItemHolder2::impl_addItem(EItem eItem) { ::osl::ResettableMutexGuard aLock(m_aLock); - TItems::const_iterator pIt; - for ( pIt = m_lItems.begin(); - pIt != m_lItems.end() ; - ++pIt ) + for ( auto const & rInfo : m_lItems ) { - const TItemInfo& rInfo = *pIt; if (rInfo.eItem == eItem) return; } @@ -93,24 +89,18 @@ void ItemHolder2::impl_addItem(EItem eItem) aNewItem.eItem = eItem; impl_newItem(aNewItem); if (aNewItem.pItem) - m_lItems.push_back(aNewItem); + m_lItems.emplace_back(std::move(aNewItem)); } void ItemHolder2::impl_releaseAllItems() { - TItems items; + std::vector< TItemInfo > items; { ::osl::MutexGuard aLock(m_aLock); items.swap(m_lItems); } - TItems::iterator pIt; - for ( pIt = items.begin(); - pIt != items.end() ; - ++pIt ) - { - delete pIt->pItem; - } + // items will be freed when the block exits } void ItemHolder2::impl_newItem(TItemInfo& rItem) @@ -118,11 +108,11 @@ void ItemHolder2::impl_newItem(TItemInfo& rItem) switch(rItem.eItem) { case EItem::CJKOptions : - rItem.pItem = new SvtCJKOptions(); + rItem.pItem.reset( new SvtCJKOptions() ); break; case EItem::CTLOptions : - rItem.pItem = new SvtCTLOptions(); + rItem.pItem.reset( new SvtCTLOptions() ); break; default: diff --git a/svl/source/config/itemholder2.hxx b/svl/source/config/itemholder2.hxx index 3246cc37b4dd..27d9f182ff03 100644 --- a/svl/source/config/itemholder2.hxx +++ b/svl/source/config/itemholder2.hxx @@ -30,7 +30,7 @@ class ItemHolder2 : private ItemHolderMutexBase // member private: - TItems m_lItems; + std::vector m_lItems; // c++ interface public: -- cgit