[Libreoffice-commits] core.git: 2 commits - include/svtools svl/source svtools/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Sep 18 09:17:42 UTC 2018


 include/svtools/valueset.hxx        |    4 +-
 svl/source/numbers/zforscan.cxx     |    8 ++---
 svtools/source/control/valueacc.cxx |    2 -
 svtools/source/control/valueset.cxx |   53 ++++++++++++++++--------------------
 4 files changed, 31 insertions(+), 36 deletions(-)

New commits:
commit 1d59238221cb3fcc97a5516fc94429a3b32e04f4
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Sep 17 16:12:42 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Sep 18 11:17:23 2018 +0200

    loplugin:useuniqueptr in ValueSet
    
    Change-Id: I0c0e32179fe1bee60c63b5db36759d5362c4402d
    Reviewed-on: https://gerrit.libreoffice.org/60628
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svtools/valueset.hxx b/include/svtools/valueset.hxx
index 5c06a0aac22e..6c0f05960e97 100644
--- a/include/svtools/valueset.hxx
+++ b/include/svtools/valueset.hxx
@@ -179,7 +179,7 @@ to be set (before Show) with SetStyle().
 
 *************************************************************************/
 
-typedef std::vector<ValueSetItem*> ValueItemList;
+typedef std::vector<std::unique_ptr<ValueSetItem>> ValueItemList;
 typedef std::vector<SvtValueSetItem*> SvtValueItemList;
 
 #define WB_ITEMBORDER           (WinBits(0x00010000))
@@ -261,7 +261,7 @@ private:
     SVT_DLLPRIVATE ValueSetItem*    ImplGetItem( size_t nPos );
     SVT_DLLPRIVATE ValueSetItem*    ImplGetFirstItem();
     SVT_DLLPRIVATE sal_uInt16          ImplGetVisibleItemCount() const;
-    SVT_DLLPRIVATE void         ImplInsertItem( ValueSetItem *const pItem, const size_t nPos );
+    SVT_DLLPRIVATE void         ImplInsertItem( std::unique_ptr<ValueSetItem> pItem, const size_t nPos );
     SVT_DLLPRIVATE tools::Rectangle    ImplGetItemRect( size_t nPos ) const;
     SVT_DLLPRIVATE void         ImplFireAccessibleEvent( short nEventId, const css::uno::Any& rOldValue, const css::uno::Any& rNewValue );
     SVT_DLLPRIVATE bool         ImplHasAccessibleListeners();
diff --git a/svtools/source/control/valueacc.cxx b/svtools/source/control/valueacc.cxx
index d661c6f48064..3b214b6c4d2f 100644
--- a/svtools/source/control/valueacc.cxx
+++ b/svtools/source/control/valueacc.cxx
@@ -420,7 +420,7 @@ uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getAccessible
 
         if( VALUESET_ITEM_NONEITEM != nItemPos )
         {
-            ValueSetItem *const pItem = mpParent->mItemList[nItemPos];
+            ValueSetItem *const pItem = mpParent->mItemList[nItemPos].get();
             xRet = pItem->GetAccessible( false/*bIsTransientChildrenDisabled*/ );
         }
     }
diff --git a/svtools/source/control/valueset.cxx b/svtools/source/control/valueset.cxx
index b3d62ef1467d..23b8a4f082f2 100644
--- a/svtools/source/control/valueset.cxx
+++ b/svtools/source/control/valueset.cxx
@@ -123,7 +123,7 @@ void ValueSet::ImplDeleteItems()
 
     for ( size_t i = 0; i < n; ++i )
     {
-        ValueSetItem* pItem = mItemList[i];
+        ValueSetItem* pItem = mItemList[i].get();
         if ( pItem->mbVisible && ImplHasAccessibleListeners() )
         {
             Any aOldAny;
@@ -133,7 +133,7 @@ void ValueSet::ImplDeleteItems()
             ImplFireAccessibleEvent(AccessibleEventId::CHILD, aOldAny, aNewAny);
         }
 
-        delete pItem;
+        mItemList[i].reset();
     }
 
     mItemList.clear();
@@ -614,7 +614,7 @@ void ValueSet::Format(vcl::RenderContext const & rRenderContext)
         }
         for (size_t i = 0; i < nItemCount; i++)
         {
-            ValueSetItem* pItem = mItemList[i];
+            ValueSetItem* pItem = mItemList[i].get();
 
             if (i >= nFirstItem && i < nLastItem)
             {
@@ -736,7 +736,7 @@ void ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt16 nIt
     if (nItemId)
     {
         const size_t nPos = GetItemPos( nItemId );
-        pItem = mItemList[ nPos ];
+        pItem = mItemList[ nPos ].get();
         aRect = ImplGetItemRect( nPos );
     }
     else if (mpNoneItem.get())
@@ -1028,12 +1028,12 @@ ValueSetItem* ValueSet::ImplGetItem( size_t nPos )
     if (nPos == VALUESET_ITEM_NONEITEM)
         return mpNoneItem.get();
     else
-        return (nPos < mItemList.size()) ? mItemList[nPos] : nullptr;
+        return (nPos < mItemList.size()) ? mItemList[nPos].get() : nullptr;
 }
 
 ValueSetItem* ValueSet::ImplGetFirstItem()
 {
-    return mItemList.size() ? mItemList[0] : nullptr;
+    return mItemList.size() ? mItemList[0].get() : nullptr;
 }
 
 sal_uInt16 ValueSet::ImplGetVisibleItemCount() const
@@ -1520,56 +1520,54 @@ void ValueSet::UserDraw( const UserDrawEvent& )
 
 void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage )
 {
-    ValueSetItem* pItem = new ValueSetItem( *this );
+    std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this ));
     pItem->mnId     = nItemId;
     pItem->meType   = VALUESETITEM_IMAGE;
     pItem->maImage  = rImage;
-    ImplInsertItem( pItem, VALUESET_APPEND );
+    ImplInsertItem( std::move(pItem), VALUESET_APPEND );
 }
 
 void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage,
                            const OUString& rText, size_t nPos,
                            bool bShowLegend )
 {
-    ValueSetItem* pItem = new ValueSetItem( *this );
+    std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this ));
     pItem->mnId     = nItemId;
     pItem->meType   = bShowLegend ? VALUESETITEM_IMAGE_AND_TEXT : VALUESETITEM_IMAGE;
     pItem->maImage  = rImage;
     pItem->maText   = rText;
-    ImplInsertItem( pItem, nPos );
+    ImplInsertItem( std::move(pItem), nPos );
 }
 
 void ValueSet::InsertItem( sal_uInt16 nItemId, const Color& rColor,
                            const OUString& rText )
 {
-    ValueSetItem* pItem = new ValueSetItem( *this );
+    std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this ));
     pItem->mnId     = nItemId;
     pItem->meType   = VALUESETITEM_COLOR;
     pItem->maColor  = rColor;
     pItem->maText   = rText;
-    ImplInsertItem( pItem, VALUESET_APPEND );
+    ImplInsertItem( std::move(pItem), VALUESET_APPEND );
 }
 
 void ValueSet::InsertItem( sal_uInt16 nItemId, size_t nPos )
 {
-    ValueSetItem* pItem = new ValueSetItem( *this );
+    std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this ));
     pItem->mnId     = nItemId;
     pItem->meType   = VALUESETITEM_USERDRAW;
-    ImplInsertItem( pItem, nPos );
+    ImplInsertItem( std::move(pItem), nPos );
 }
 
-void ValueSet::ImplInsertItem( ValueSetItem *const pItem, const size_t nPos )
+void ValueSet::ImplInsertItem( std::unique_ptr<ValueSetItem> pItem, const size_t nPos )
 {
     DBG_ASSERT( pItem->mnId, "ValueSet::InsertItem(): ItemId == 0" );
     DBG_ASSERT( GetItemPos( pItem->mnId ) == VALUESET_ITEM_NOTFOUND,
                 "ValueSet::InsertItem(): ItemId already exists" );
 
     if ( nPos < mItemList.size() ) {
-        ValueItemList::iterator it = mItemList.begin();
-        ::std::advance( it, nPos );
-        mItemList.insert( it, pItem );
+        mItemList.insert( mItemList.begin() + nPos, std::move(pItem) );
     } else {
-        mItemList.push_back( pItem );
+        mItemList.push_back( std::move(pItem) );
     }
 
     queue_resize();
@@ -1607,10 +1605,7 @@ void ValueSet::RemoveItem( sal_uInt16 nItemId )
         return;
 
     if ( nPos < mItemList.size() ) {
-        ValueItemList::iterator it = mItemList.begin();
-        ::std::advance( it, nPos );
-        delete *it;
-        mItemList.erase( it );
+        mItemList.erase( mItemList.begin() + nPos );
     }
 
     // reset variables
@@ -1838,7 +1833,7 @@ void ValueSet::SelectItem( sal_uInt16 nItemId )
 
         ValueSetItem* pItem;
         if( nPos != VALUESET_ITEM_NOTFOUND )
-            pItem = mItemList[nPos];
+            pItem = mItemList[nPos].get();
         else
             pItem = mpNoneItem.get();
 
@@ -1879,7 +1874,7 @@ void ValueSet::SetItemImage( sal_uInt16 nItemId, const Image& rImage )
     if ( nPos == VALUESET_ITEM_NOTFOUND )
         return;
 
-    ValueSetItem* pItem = mItemList[nPos];
+    ValueSetItem* pItem = mItemList[nPos].get();
     pItem->meType  = VALUESETITEM_IMAGE;
     pItem->maImage = rImage;
 
@@ -1909,7 +1904,7 @@ void ValueSet::SetItemColor( sal_uInt16 nItemId, const Color& rColor )
     if ( nPos == VALUESET_ITEM_NOTFOUND )
         return;
 
-    ValueSetItem* pItem = mItemList[nPos];
+    ValueSetItem* pItem = mItemList[nPos].get();
     pItem->meType  = VALUESETITEM_COLOR;
     pItem->maColor = rColor;
 
@@ -1939,7 +1934,7 @@ void ValueSet::SetItemData( sal_uInt16 nItemId, void* pData )
     if ( nPos == VALUESET_ITEM_NOTFOUND )
         return;
 
-    ValueSetItem* pItem = mItemList[nPos];
+    ValueSetItem* pItem = mItemList[nPos].get();
     pItem->mpData = pData;
 
     if ( pItem->meType == VALUESETITEM_USERDRAW )
@@ -1972,7 +1967,7 @@ void ValueSet::SetItemText(sal_uInt16 nItemId, const OUString& rText)
         return;
 
 
-    ValueSetItem* pItem = mItemList[nPos];
+    ValueSetItem* pItem = mItemList[nPos].get();
 
     // Remember old and new name for accessibility event.
     Any aOldName;
@@ -2215,7 +2210,7 @@ Size ValueSet::GetLargestItemSize()
 {
     Size aLargestItem;
 
-    for (ValueSetItem* pItem : mItemList)
+    for (std::unique_ptr<ValueSetItem>& pItem : mItemList)
     {
         if (!pItem->mbVisible)
             continue;
commit 1c54cd50d5a393a09e9f82bc24100683c1ba24ed
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Mon Sep 17 22:43:46 2018 +0200
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Tue Sep 18 11:17:17 2018 +0200

    Use !startsWith() instead of indexOf()!=0
    
    Faster and even easier to read.
    
    Change-Id: I0146f70ea250e68887ac5d8dd5a10fe7e6a90eeb
    Reviewed-on: https://gerrit.libreoffice.org/60648
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins

diff --git a/svl/source/numbers/zforscan.cxx b/svl/source/numbers/zforscan.cxx
index b3589ed7c601..bb54df73ef02 100644
--- a/svl/source/numbers/zforscan.cxx
+++ b/svl/source/numbers/zforscan.cxx
@@ -698,7 +698,7 @@ short ImpSvNumberformatScan::GetKeyWord( const OUString& sSymbol, sal_Int32 nPos
     {
         // skip the gap of colors et al between new and old keywords and search on
         i = NF_KEY_LASTKEYWORD;
-        while ( i > 0 && sString.indexOf(rKeyword[i]) != 0 )
+        while ( i > 0 && !sString.startsWith( rKeyword[i]) )
         {
             i--;
         }
@@ -707,7 +707,7 @@ short ImpSvNumberformatScan::GetKeyWord( const OUString& sSymbol, sal_Int32 nPos
             // found something, but maybe it's something else?
             // e.g. new NNN is found in NNNN, for NNNN we must search on
             short j = i - 1;
-            while ( j > 0 && sString.indexOf(rKeyword[j]) != 0 )
+            while ( j > 0 && !sString.startsWith( rKeyword[j]) )
             {
                 j--;
             }
@@ -722,7 +722,7 @@ short ImpSvNumberformatScan::GetKeyWord( const OUString& sSymbol, sal_Int32 nPos
             // are localized. That was already checked in
             // SetDependentKeywords().
             i = NF_KEY_LASTKEYWORD;
-            while ( i > 0 && sString.indexOf(sEnglishKeyword[i]) != 0 )
+            while ( i > 0 && !sString.startsWith( sEnglishKeyword[i]) )
             {
                 i--;
             }
@@ -731,7 +731,7 @@ short ImpSvNumberformatScan::GetKeyWord( const OUString& sSymbol, sal_Int32 nPos
                 // found something, but maybe it's something else?
                 // e.g. new NNN is found in NNNN, for NNNN we must search on
                 short j = i - 1;
-                while ( j > 0 && sString.indexOf(sEnglishKeyword[j]) != 0 )
+                while ( j > 0 && !sString.startsWith( sEnglishKeyword[j]) )
                 {
                     j--;
                 }


More information about the Libreoffice-commits mailing list