diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-02-16 18:39:23 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-02-18 07:41:05 +0100 |
commit | 44841a6778821be3e68ab15819b39064b20e968f (patch) | |
tree | 8e9119cf35764f18f5b008e7758c6f950306fb8c /idlc | |
parent | bcfbd24be02d2de5d4d27c147dc58c4515a9a0f5 (diff) |
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 <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'idlc')
-rw-r--r-- | idlc/source/astenum.cxx | 13 | ||||
-rw-r--r-- | idlc/source/astscope.cxx | 14 | ||||
-rw-r--r-- | idlc/source/astservice.cxx | 24 |
3 files changed, 14 insertions, 37 deletions
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<AstConstant*>(pDecl); - - if (pConst->getConstValue()->compareLong(pExpr)) - return pConst; + iter = std::find_if(iter, end, [&pExpr](AstDeclaration* pDecl) { + return static_cast<AstConstant*>(pDecl)->getConstValue()->compareLong(pExpr); }); - ++iter; - } + if (iter != end) + return static_cast<AstConstant*>(*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<sal_uInt16>(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(); + }); } } } |