[Libreoffice-commits] core.git: sc/qa sc/source

Takeshi Abe tabe at fixedpoint.jp
Tue May 19 00:36:56 PDT 2015


 sc/qa/unit/subsequent_filters-test.cxx   |    3 ++-
 sc/source/core/data/column2.cxx          |    3 ++-
 sc/source/core/data/dpdimsave.cxx        |    2 +-
 sc/source/core/data/dpgroup.cxx          |    7 ++-----
 sc/source/core/data/dpobject.cxx         |   12 +++++-------
 sc/source/core/tool/rangelst.cxx         |   11 +++--------
 sc/source/core/tool/userlist.cxx         |    5 ++---
 sc/source/filter/excel/xelink.cxx        |   13 +++----------
 sc/source/filter/excel/xestyle.cxx       |    4 ++--
 sc/source/ui/docshell/externalrefmgr.cxx |    4 +---
 10 files changed, 23 insertions(+), 41 deletions(-)

New commits:
commit 023e945ab298bfa6e73eb6b82789fc2fca97f247
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Mon May 18 15:16:17 2015 +0900

    sc: simplify code by replacing std::find_if with std::any_of
    
    ... or std::none_of.
    
    Change-Id: I84808bedbaf098f7c4c987ea62d0ccc4a2b7c2f5
    Reviewed-on: https://gerrit.libreoffice.org/15780
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: David Tardon <dtardon at redhat.com>

diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index b0286e6..c0b12d3 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -75,6 +75,7 @@
 
 #include "helper/qahelper.hxx"
 #include "helper/shared_test_impl.hxx"
+#include <algorithm>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -1701,7 +1702,7 @@ public:
 
 bool hasDimension(const std::vector<const ScDPSaveDimension*>& rDims, const OUString& aName)
 {
-    return std::find_if(rDims.begin(), rDims.end(), FindDimByName(aName)) != rDims.end();
+    return std::any_of(rDims.begin(), rDims.end(), FindDimByName(aName));
 }
 
 }
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 9301078..eca99eb 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -67,6 +67,7 @@
 #include <formula/vectortoken.hxx>
 
 #include <boost/scoped_ptr.hpp>
+#include <algorithm>
 
 // factor from font size to optimal cell height (text width)
 #define SC_ROT_BREAK_FACTOR     6
@@ -2481,7 +2482,7 @@ bool hasNonEmpty( const sc::FormulaGroupContext::StrArrayType& rArray, SCROW nRo
     std::advance(it, nRow1);
     sc::FormulaGroupContext::StrArrayType::const_iterator itEnd = it;
     std::advance(itEnd, nRow2-nRow1+1);
-    return std::find_if(it, itEnd, NonNullStringFinder()) != itEnd;
+    return std::any_of(it, itEnd, NonNullStringFinder());
 }
 
 }
diff --git a/sc/source/core/data/dpdimsave.cxx b/sc/source/core/data/dpdimsave.cxx
index 40dcb3f..ffa721d 100644
--- a/sc/source/core/data/dpdimsave.cxx
+++ b/sc/source/core/data/dpdimsave.cxx
@@ -602,7 +602,7 @@ bool ScDPDimensionSaveData::operator==( const ScDPDimensionSaveData& ) const
 
 void ScDPDimensionSaveData::AddGroupDimension( const ScDPSaveGroupDimension& rGroupDim )
 {
-    OSL_ENSURE( ::std::find_if( maGroupDims.begin(), maGroupDims.end(), ScDPSaveGroupDimNameFunc( rGroupDim.GetGroupDimName() ) ) == maGroupDims.end(),
+    OSL_ENSURE( ::std::none_of( maGroupDims.begin(), maGroupDims.end(), ScDPSaveGroupDimNameFunc( rGroupDim.GetGroupDimName() ) ),
         "ScDPDimensionSaveData::AddGroupDimension - group dimension exists already" );
     // ReplaceGroupDimension() adds new or replaces existing
     ReplaceGroupDimension( rGroupDim );
diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx
index 49edcfb..b9c5572 100644
--- a/sc/source/core/data/dpgroup.cxx
+++ b/sc/source/core/data/dpgroup.cxx
@@ -39,6 +39,7 @@
 #include <unordered_map>
 #include <unordered_set>
 #include <vector>
+#include <algorithm>
 
 using namespace ::com::sun::star;
 using ::com::sun::star::uno::Any;
@@ -755,11 +756,7 @@ void ScDPGroupTableData::ModifyFilterCriteria(vector<ScDPFilteredCache::Criterio
                         continue;
 
                     // Make sure this group name equals one of the match values.
-                    std::vector<ScDPItemData>::iterator it =
-                        std::find_if(
-                            aMatchValues.begin(), aMatchValues.end(), FindCaseInsensitive(pGrpItem->GetName()));
-
-                    if (it == aMatchValues.end())
+                    if (std::none_of(aMatchValues.begin(), aMatchValues.end(), FindCaseInsensitive(pGrpItem->GetName())))
                         continue;
 
                     pGrpItem->FillGroupFilter(*pGrpFilter);
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 30884cc..ab982c4 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -78,6 +78,7 @@
 #include <utility>
 #include <vector>
 #include <memory>
+#include <algorithm>
 
 using namespace com::sun::star;
 using ::std::vector;
@@ -2588,7 +2589,7 @@ void ScDPObject::ConvertOrientation(
             {
                 //  if set via api, a data column may occur several times
                 //  (if the function hasn't been changed yet) -> also look for duplicate data column
-                bFirst = std::find_if(itrBeg, itr, FindByOriginalDim(nCol)) == itr;
+                bFirst = std::none_of(itrBeg, itr, FindByOriginalDim(nCol));
             }
 
             sheet::GeneralFunction eFunc = ScDataPilotConversion::FirstFunc(rField.nFuncMask);
@@ -3682,20 +3683,17 @@ ScRangeList ScDPCollection::GetAllTableRanges( SCTAB nTab ) const
 
 bool ScDPCollection::IntersectsTableByColumns( SCCOL nCol1, SCCOL nCol2, SCROW nRow, SCTAB nTab ) const
 {
-    return std::find_if(
-        maTables.begin(), maTables.end(), FindIntersetingTableByColumns(nCol1, nCol2, nRow, nTab)) != maTables.end();
+    return std::any_of(maTables.begin(), maTables.end(), FindIntersetingTableByColumns(nCol1, nCol2, nRow, nTab));
 }
 
 bool ScDPCollection::IntersectsTableByRows( SCCOL nCol, SCROW nRow1, SCROW nRow2, SCTAB nTab ) const
 {
-    return std::find_if(
-        maTables.begin(), maTables.end(), FindIntersectingTableByRows(nCol, nRow1, nRow2, nTab)) != maTables.end();
+    return std::any_of(maTables.begin(), maTables.end(), FindIntersectingTableByRows(nCol, nRow1, nRow2, nTab));
 }
 
 bool ScDPCollection::HasTable( const ScRange& rRange ) const
 {
-    return std::find_if(
-        maTables.begin(), maTables.end(), FindIntersectingTable(rRange)) != maTables.end();
+    return std::any_of(maTables.begin(), maTables.end(), FindIntersectingTable(rRange));
 }
 
 #if DEBUG_PIVOT_TABLE
diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index 44d740f..8b1bb08 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -28,6 +28,7 @@
 #include "rechead.hxx"
 #include "compiler.hxx"
 #include <boost/checked_delete.hpp>
+#include <algorithm>
 
 using ::std::vector;
 using ::std::advance;
@@ -1054,18 +1055,12 @@ void ScRangeList::Append( const ScRange& rRange )
 
 bool ScRangeList::Intersects( const ScRange& rRange ) const
 {
-    const_iterator itrEnd = maRanges.end();
-    const_iterator itr =
-        find_if(maRanges.begin(), itrEnd, FindIntersectingRange<ScRange>(rRange));
-    return itr != itrEnd;
+    return std::any_of(maRanges.begin(), maRanges.end(), FindIntersectingRange<ScRange>(rRange));
 }
 
 bool ScRangeList::In( const ScRange& rRange ) const
 {
-    const_iterator itrEnd = maRanges.end();
-    const_iterator itr =
-        find_if(maRanges.begin(), itrEnd, FindEnclosingRange<ScRange>(rRange));
-    return itr != itrEnd;
+    return std::any_of(maRanges.begin(), maRanges.end(), FindEnclosingRange<ScRange>(rRange));
 }
 
 size_t ScRangeList::GetCellCount() const
diff --git a/sc/source/core/tool/userlist.cxx b/sc/source/core/tool/userlist.cxx
index 6f594df..411a2fd 100644
--- a/sc/source/core/tool/userlist.cxx
+++ b/sc/source/core/tool/userlist.cxx
@@ -26,6 +26,7 @@
 #include <unotools/transliterationwrapper.hxx>
 
 #include <boost/bind.hpp>
+#include <algorithm>
 
 namespace {
 
@@ -317,9 +318,7 @@ bool ScUserList::operator!=( const ScUserList& r ) const
 
 bool ScUserList::HasEntry( const OUString& rStr ) const
 {
-    DataType::const_iterator itr = ::std::find_if(
-        maData.begin(), maData.end(), ::boost::bind(&ScUserListData::GetString, _1) == rStr);
-    return itr != maData.end();
+    return ::std::any_of(maData.begin(), maData.end(), ::boost::bind(&ScUserListData::GetString, _1) == rStr);
 }
 
 ScUserList::iterator ScUserList::begin()
diff --git a/sc/source/filter/excel/xelink.cxx b/sc/source/filter/excel/xelink.cxx
index 6fd5e82..a936f45 100644
--- a/sc/source/filter/excel/xelink.cxx
+++ b/sc/source/filter/excel/xelink.cxx
@@ -33,7 +33,6 @@
 #include <memory>
 
 using ::std::unique_ptr;
-using ::std::find_if;
 using ::std::vector;
 using ::com::sun::star::uno::Any;
 
@@ -1884,9 +1883,7 @@ void XclExpSupbookBuffer::StoreCell( sal_uInt16 nFileId, const OUString& rTabNam
         return;
 
     FindSBIndexEntry f(nSupbookId, nSheetId);
-    XclExpSBIndexVec::iterator itrEnd = maSBIndexVec.end();
-    XclExpSBIndexVec::const_iterator itr = find_if(maSBIndexVec.begin(), itrEnd, f);
-    if (itr == itrEnd)
+    if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(), f))
     {
         maSBIndexVec.push_back(XclExpSBIndex());
         XclExpSBIndex& r = maSBIndexVec.back();
@@ -1950,9 +1947,7 @@ void XclExpSupbookBuffer::StoreCellRange( sal_uInt16 nFileId, const OUString& rT
     {
         sal_uInt16 nSheetId = nFirstSheetId + static_cast<sal_uInt16>(nTab);
         FindSBIndexEntry f(nSupbookId, nSheetId);
-        XclExpSBIndexVec::iterator itrEnd = maSBIndexVec.end();
-        XclExpSBIndexVec::const_iterator itr = find_if(maSBIndexVec.begin(), itrEnd, f);
-        if (itr == itrEnd)
+        if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(), f))
         {
             maSBIndexVec.push_back(XclExpSBIndex());
             XclExpSBIndex& r = maSBIndexVec.back();
@@ -2055,9 +2050,7 @@ XclExpXti XclExpSupbookBuffer::GetXti( sal_uInt16 nFileId, const OUString& rTabN
             return aXti;
 
         FindSBIndexEntry f(nSupbookId, nSheetId);
-        XclExpSBIndexVec::iterator itrEnd = maSBIndexVec.end();
-        XclExpSBIndexVec::const_iterator itr = find_if(maSBIndexVec.begin(), itrEnd, f);
-        if (itr == itrEnd)
+        if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(), f))
         {
             maSBIndexVec.push_back(XclExpSBIndex());
             XclExpSBIndex& r = maSBIndexVec.back();
diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx
index 46ecbfb..df5c75b 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -2986,12 +2986,12 @@ void XclExpXFBuffer::AppendXFIndex( sal_uInt32 nXFId )
 
 void XclExpXFBuffer::AddBorderAndFill( const XclExpXF& rXF )
 {
-    if( std::find_if( maBorders.begin(), maBorders.end(), XclExpBorderPred( rXF.GetBorderData() ) ) == maBorders.end() )
+    if( std::none_of( maBorders.begin(), maBorders.end(), XclExpBorderPred( rXF.GetBorderData() ) ) )
     {
         maBorders.push_back( rXF.GetBorderData() );
     }
 
-    if( std::find_if( maFills.begin(), maFills.end(), XclExpFillPred( rXF.GetAreaData() ) ) == maFills.end() )
+    if( std::none_of( maFills.begin(), maFills.end(), XclExpFillPred( rXF.GetAreaData() ) ) )
     {
         maFills.push_back( rXF.GetAreaData() );
     }
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 6791f57..36dc18d 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -2591,9 +2591,7 @@ bool ScExternalRefManager::hasExternalFile(sal_uInt16 nFileId) const
 
 bool ScExternalRefManager::hasExternalFile(const OUString& rFile) const
 {
-    vector<SrcFileData>::const_iterator itrBeg = maSrcFiles.begin(), itrEnd = maSrcFiles.end();
-    vector<SrcFileData>::const_iterator itr = find_if(itrBeg, itrEnd, FindSrcFileByName(rFile));
-    return itr != itrEnd;
+    return ::std::any_of(maSrcFiles.begin(), maSrcFiles.end(), FindSrcFileByName(rFile));
 }
 
 const ScExternalRefManager::SrcFileData* ScExternalRefManager::getExternalFileData(sal_uInt16 nFileId) const


More information about the Libreoffice-commits mailing list