From 44841a6778821be3e68ab15819b39064b20e968f Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Sat, 16 Feb 2019 18:39:23 +0300 Subject: Simplify containers iterations in [f-l]* Use range-based loop or replace with STL functions Change-Id: Ib3fab47318d1bfbb4df8f886a8cd9596525a420f Reviewed-on: https://gerrit.libreoffice.org/67914 Reviewed-by: Noel Grandin Tested-by: Noel Grandin --- idlc/source/astenum.cxx | 13 ++++--------- idlc/source/astscope.cxx | 14 ++------------ idlc/source/astservice.cxx | 24 ++++++++---------------- 3 files changed, 14 insertions(+), 37 deletions(-) (limited to 'idlc') diff --git a/idlc/source/astenum.cxx b/idlc/source/astenum.cxx index 69fb0c7bfd89..4254f7264eaa 100644 --- a/idlc/source/astenum.cxx +++ b/idlc/source/astenum.cxx @@ -38,16 +38,11 @@ AstConstant* AstEnum::checkValue(AstExpression* pExpr) DeclList::const_iterator iter = getIteratorBegin(); DeclList::const_iterator end = getIteratorEnd(); - while ( iter != end) - { - AstDeclaration* pDecl = *iter; - AstConstant* pConst = static_cast(pDecl); - - if (pConst->getConstValue()->compareLong(pExpr)) - return pConst; + iter = std::find_if(iter, end, [&pExpr](AstDeclaration* pDecl) { + return static_cast(pDecl)->getConstValue()->compareLong(pExpr); }); - ++iter; - } + if (iter != end) + return static_cast(*iter); if ( pExpr->getExprValue()->u.lval > m_enumValueCount ) m_enumValueCount = pExpr->getExprValue()->u.lval + 1; diff --git a/idlc/source/astscope.cxx b/idlc/source/astscope.cxx index 1ddda3984458..9af691501a8a 100644 --- a/idlc/source/astscope.cxx +++ b/idlc/source/astscope.cxx @@ -85,18 +85,8 @@ AstDeclaration* AstScope::addDeclaration(AstDeclaration* pDecl) sal_uInt16 AstScope::getNodeCount(NodeType nodeType) const { - DeclList::const_iterator iter = getIteratorBegin(); - DeclList::const_iterator end = getIteratorEnd(); - sal_uInt16 count = 0; - - while ( iter != end ) - { - AstDeclaration* pDecl = *iter; - if ( pDecl->getNodeType() == nodeType ) - count++; - ++iter; - } - return count; + return static_cast(std::count_if(getIteratorBegin(), getIteratorEnd(), + [&nodeType](const AstDeclaration* pDecl) { return pDecl->getNodeType() == nodeType; })); } AstDeclaration* AstScope::lookupByName(const OString& scopedName) diff --git a/idlc/source/astservice.cxx b/idlc/source/astservice.cxx index f92aa6ab94c4..c90ded6b4d7a 100644 --- a/idlc/source/astservice.cxx +++ b/idlc/source/astservice.cxx @@ -37,22 +37,14 @@ bool AstService::checkLastConstructor() const { } sal_uInt32 n = ctor->nMembers(); if (n == last->nMembers()) { - for (DeclList::const_iterator i1(ctor->getIteratorBegin()), - i2(last->getIteratorBegin()); - i1 != ctor->getIteratorEnd(); ++i1, ++i2) - { - sal_Int32 r1; - AstDeclaration const * t1 = deconstructAndResolveTypedefs( - static_cast< AstMember * >(*i1)->getType(), &r1); - sal_Int32 r2; - AstDeclaration const * t2 = deconstructAndResolveTypedefs( - static_cast< AstMember * >(*i2)->getType(), &r2); - if (r1 != r2 || t1->getScopedName() != t2->getScopedName()) - { - return false; - } - } - return true; + return std::equal(ctor->getIteratorBegin(), ctor->getIteratorEnd(), last->getIteratorBegin(), + [](AstDeclaration* a, AstDeclaration* b) { + sal_Int32 r1; + AstDeclaration const * t1 = deconstructAndResolveTypedefs(static_cast< AstMember * >(a)->getType(), &r1); + sal_Int32 r2; + AstDeclaration const * t2 = deconstructAndResolveTypedefs(static_cast< AstMember * >(b)->getType(), &r2); + return r1 == r2 && t1->getScopedName() == t2->getScopedName(); + }); } } } -- cgit