[Libreoffice-commits] core.git: xmlhelp/source xmlreader/source xmlscript/source xmlsecurity/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Sep 15 07:06:58 UTC 2018


 xmlhelp/source/cxxhelp/provider/databases.cxx |   26 +----
 xmlhelp/source/treeview/tvread.cxx            |    8 -
 xmlreader/source/xmlreader.cxx                |   13 +-
 xmlscript/source/xml_helper/xml_impctx.cxx    |    8 -
 xmlsecurity/source/framework/buffernode.cxx   |  122 +++++++-------------------
 5 files changed, 52 insertions(+), 125 deletions(-)

New commits:
commit 87b24ddbba056b4887ad4613a84686ab3d2218cd
Author:     Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Thu Sep 13 22:09:43 2018 +0300
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Sep 15 09:06:38 2018 +0200

    Simplify containers iterations in xmlhelp, xmlreader, xmlscript, xmlsecurity
    
    Use range-based loop or replace with functions from std algorithm.
    
    Change-Id: I5b1859da37c2a6c6e5e70602287bfc2ada951893
    Reviewed-on: https://gerrit.libreoffice.org/60463
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx
index fa94f56a9a68..88cedb7bfefd 100644
--- a/xmlhelp/source/cxxhelp/provider/databases.cxx
+++ b/xmlhelp/source/cxxhelp/provider/databases.cxx
@@ -167,34 +167,20 @@ Databases::~Databases()
 
     {
         // DatabasesTable
-        DatabasesTable::iterator it = m_aDatabases.begin();
-        while( it != m_aDatabases.end() )
-        {
-            delete it->second;
-            ++it;
-        }
+        for (auto& rDatabase : m_aDatabases)
+            delete rDatabase.second;
     }
 
     {
         //  ModInfoTable
-
-        ModInfoTable::iterator it = m_aModInfo.begin();
-        while( it != m_aModInfo.end() )
-        {
-            delete it->second;
-            ++it;
-        }
+        for (auto& rModInfo : m_aModInfo)
+            delete rModInfo.second;
     }
 
     {
         // KeywordInfoTable
-
-        KeywordInfoTable::iterator it = m_aKeywordInfo.begin();
-        while( it != m_aKeywordInfo.end() )
-        {
-            delete it->second;
-            ++it;
-        }
+        for (auto& rKeywordInfo : m_aKeywordInfo)
+            delete rKeywordInfo.second;
     }
 }
 
diff --git a/xmlhelp/source/treeview/tvread.cxx b/xmlhelp/source/treeview/tvread.cxx
index 2d98eb7755dd..c8006bee590f 100644
--- a/xmlhelp/source/treeview/tvread.cxx
+++ b/xmlhelp/source/treeview/tvread.cxx
@@ -503,11 +503,11 @@ TVChildTarget::SearchAndInsert(std::unique_ptr<TVDom> p, TVDom* tvDom)
     }
     else
     {
-        i = tvDom->children.begin();
-        while ((i!=tvDom->children.end()) && (p != nullptr))
+        for (auto& child : tvDom->children)
         {
-            p = SearchAndInsert(std::move(p), i->get());
-            ++i;
+            p = SearchAndInsert(std::move(p), child.get());
+            if (p == nullptr)
+                break;
         }
         return p;
     }
diff --git a/xmlreader/source/xmlreader.cxx b/xmlreader/source/xmlreader.cxx
index 699567a53a32..58f3ec88ebb6 100644
--- a/xmlreader/source/xmlreader.cxx
+++ b/xmlreader/source/xmlreader.cxx
@@ -184,13 +184,12 @@ Span XmlReader::getAttributeValue(bool fullyNormalize) {
 }
 
 int XmlReader::getNamespaceId(Span const & prefix) const {
-    for (NamespaceList::const_reverse_iterator i(namespaces_.rbegin());
-         i != namespaces_.rend(); ++i)
-    {
-        if (prefix.equals(i->prefix)) {
-            return i->nsId;
-        }
-    }
+    auto i = std::find_if(namespaces_.crbegin(), namespaces_.crend(),
+        [&prefix](const NamespaceData& rNamespaceData) { return prefix.equals(rNamespaceData.prefix); });
+
+    if (i != namespaces_.rend())
+        return i->nsId;
+
     return NAMESPACE_UNKNOWN;
 }
 
diff --git a/xmlscript/source/xml_helper/xml_impctx.cxx b/xmlscript/source/xml_helper/xml_impctx.cxx
index face4f5ca01f..dfb4b8141be6 100644
--- a/xmlscript/source/xml_helper/xml_impctx.cxx
+++ b/xmlscript/source/xml_helper/xml_impctx.cxx
@@ -395,12 +395,10 @@ sal_Int32 DocumentHandlerImpl::getUidByUri( OUString const & Uri )
 OUString DocumentHandlerImpl::getUriByUid( sal_Int32 Uid )
 {
     MGuard guard( m_pMutex );
-    t_OUString2LongMap::const_iterator iPos( m_URI2Uid.begin() );
-    t_OUString2LongMap::const_iterator const iEnd( m_URI2Uid.end() );
-    for ( ; iPos != iEnd; ++iPos )
+    for (const auto& rURIUid : m_URI2Uid)
     {
-        if (iPos->second == Uid)
-            return iPos->first;
+        if (rURIUid.second == Uid)
+            return rURIUid.first;
     }
     throw container::NoSuchElementException( "no such xmlns uid!" , static_cast< OWeakObject * >(this) );
 }
diff --git a/xmlsecurity/source/framework/buffernode.cxx b/xmlsecurity/source/framework/buffernode.cxx
index d1cd8d17ed44..3de2c4ef5271 100644
--- a/xmlsecurity/source/framework/buffernode.cxx
+++ b/xmlsecurity/source/framework/buffernode.cxx
@@ -63,23 +63,12 @@ bool BufferNode::isECOfBeforeModifyIncluded(sal_Int32 nIgnoredSecurityId) const
  *  bExist - true if a match found, false otherwise
  ******************************************************************************/
 {
-    bool rc = false;
-    std::vector< const ElementCollector* >::const_iterator ii = m_vElementCollectors.begin();
-
-    for( ; ii != m_vElementCollectors.end() ; ++ii )
-    {
-        ElementCollector* pElementCollector = const_cast<ElementCollector*>(*ii);
-
-        if ((nIgnoredSecurityId == cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID ||
-             pElementCollector->getSecurityId() != nIgnoredSecurityId) &&
-            (pElementCollector->getPriority() == cssxc::sax::ElementMarkPriority_BEFOREMODIFY))
-        {
-            rc = true;
-            break;
-        }
-    }
-
-    return rc;
+    return std::any_of(m_vElementCollectors.cbegin(), m_vElementCollectors.cend(),
+        [nIgnoredSecurityId](const ElementCollector* pElementCollector) {
+            return (nIgnoredSecurityId == cssxc::sax::ConstOfSecurityId::UNDEFINEDSECURITYID ||
+                    pElementCollector->getSecurityId() != nIgnoredSecurityId) &&
+                   (pElementCollector->getPriority() == cssxc::sax::ElementMarkPriority_BEFOREMODIFY);
+        });
 }
 
 void BufferNode::setReceivedAll()
@@ -151,16 +140,11 @@ void BufferNode::removeElementCollector(const ElementCollector* pElementCollecto
  *  empty
  ******************************************************************************/
 {
-    std::vector< const ElementCollector* >::iterator ii = m_vElementCollectors.begin();
-
-    for( ; ii != m_vElementCollectors.end() ; ++ii )
+    auto ii = std::find(m_vElementCollectors.begin(), m_vElementCollectors.end(), pElementCollector);
+    if (ii != m_vElementCollectors.end())
     {
-        if( *ii == pElementCollector )
-        {
-            m_vElementCollectors.erase( ii );
-            const_cast<ElementCollector*>(pElementCollector)->setBufferNode(nullptr);
-            break;
-        }
+        m_vElementCollectors.erase( ii );
+        const_cast<ElementCollector*>(pElementCollector)->setBufferNode(nullptr);
     }
 }
 
@@ -217,20 +201,19 @@ OUString BufferNode::printChildren() const
  ******************************************************************************/
 {
     OUStringBuffer rc;
-    std::vector< const ElementCollector* >::const_iterator ii = m_vElementCollectors.begin();
 
-    for( ; ii != m_vElementCollectors.end() ; ++ii )
+    for( const ElementCollector* ii : m_vElementCollectors )
     {
-        rc.append("BufID=").append(OUString::number((*ii)->getBufferId()));
+        rc.append("BufID=").append(OUString::number(ii->getBufferId()));
 
-        if ((*ii)->getModify())
+        if (ii->getModify())
         {
             rc.append("[M]");
         }
 
         rc.append(",Pri=");
 
-        switch ((*ii)->getPriority())
+        switch (ii->getPriority())
         {
             case cssxc::sax::ElementMarkPriority_BEFOREMODIFY:
                 rc.append("BEFOREMODIFY");
@@ -243,7 +226,7 @@ OUString BufferNode::printChildren() const
                 break;
         }
 
-        rc.append("(SecID=").append(OUString::number((*ii)->getSecurityId())).append(") ");
+        rc.append("(SecID=").append(OUString::number(ii->getSecurityId())).append(") ");
     }
 
     return rc.makeStringAndClear();
@@ -410,16 +393,9 @@ void BufferNode::removeChild(const BufferNode* pChild)
  *  empty
  ******************************************************************************/
 {
-    std::vector< const BufferNode* >::iterator ii = m_vChildren.begin();
-
-    for( ; ii != m_vChildren.end() ; ++ii )
-    {
-        if( *ii == pChild )
-        {
-            m_vChildren.erase( ii );
-            break;
-        }
-    }
+    auto ii = std::find(m_vChildren.begin(), m_vChildren.end(), pChild);
+    if (ii != m_vChildren.end())
+        m_vChildren.erase( ii );
 }
 
 sal_Int32 BufferNode::indexOfChild(const BufferNode* pChild) const
@@ -442,27 +418,11 @@ sal_Int32 BufferNode::indexOfChild(const BufferNode* pChild) const
  *          is not found, -1 is returned.
  ******************************************************************************/
 {
-    sal_Int32 nIndex = 0;
-    bool bFound = false;
-
-    std::vector< const BufferNode * >::const_iterator ii = m_vChildren.begin();
-
-    for( ; ii != m_vChildren.end() ; ++ii )
-    {
-        if( *ii == pChild )
-        {
-            bFound = true;
-            break;
-        }
-        nIndex++;
-    }
-
-    if (!bFound )
-    {
-        nIndex = -1;
-    }
+    auto ii = std::find(m_vChildren.begin(), m_vChildren.end(), pChild);
+    if (ii == m_vChildren.end())
+        return -1;
 
-    return nIndex;
+    return std::distance(m_vChildren.begin(), ii);
 }
 
 
@@ -525,24 +485,13 @@ const BufferNode* BufferNode::isAncestor(const BufferNode* pDescendant) const
 
     if (pDescendant != nullptr)
     {
-        std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
+        auto ii = std::find_if(m_vChildren.cbegin(), m_vChildren.cend(),
+            [&pDescendant](const BufferNode* pChild) {
+                return (pChild == pDescendant) || (pChild->isAncestor(pDescendant) != nullptr);
+            });
 
-        for( ; ii != m_vChildren.end() ; ++ii )
-        {
-            BufferNode* pChild = const_cast<BufferNode*>(*ii);
-
-            if (pChild == pDescendant)
-            {
-                rc = pChild;
-                break;
-            }
-
-            if (pChild->isAncestor(pDescendant) != nullptr)
-            {
-                rc = pChild;
-                break;
-            }
-        }
+        if (ii != m_vChildren.end())
+            rc = const_cast<BufferNode*>(*ii);
     }
 
     return rc;
@@ -687,11 +636,9 @@ void BufferNode::notifyBranch()
  *  empty
  ******************************************************************************/
 {
-    std::vector< const BufferNode* >::const_iterator ii = m_vChildren.begin();
-
-    for( ; ii != m_vChildren.end() ; ++ii )
+    for( const BufferNode* ii : m_vChildren )
     {
-        BufferNode* pBufferNode = const_cast<BufferNode*>(*ii);
+        BufferNode* pBufferNode = const_cast<BufferNode*>(ii);
         pBufferNode->elementCollectorNotify();
         pBufferNode->notifyBranch();
     }
@@ -725,10 +672,8 @@ void BufferNode::elementCollectorNotify()
         /*
          * get the max priority among ElementCollectors on this BufferNode
          */
-        std::vector< const ElementCollector* >::const_iterator ii = m_vElementCollectors.begin();
-        for( ; ii != m_vElementCollectors.end() ; ++ii )
+        for( const ElementCollector* pElementCollector : m_vElementCollectors )
         {
-            ElementCollector* pElementCollector = const_cast<ElementCollector*>(*ii);
             nPriority = pElementCollector->getPriority();
             if (nPriority > nMaxPriority)
             {
@@ -737,11 +682,10 @@ void BufferNode::elementCollectorNotify()
         }
 
         std::vector< const ElementCollector* > vElementCollectors( m_vElementCollectors );
-        ii = vElementCollectors.begin();
 
-        for( ; ii != vElementCollectors.end() ; ++ii )
+        for( const ElementCollector* ii : vElementCollectors )
         {
-            ElementCollector* pElementCollector = const_cast<ElementCollector*>(*ii);
+            ElementCollector* pElementCollector = const_cast<ElementCollector*>(ii);
             nPriority = pElementCollector->getPriority();
             bool bToModify = pElementCollector->getModify();
 


More information about the Libreoffice-commits mailing list