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@collabora.co.uk>
This commit is contained in:
Arkadiy Illarionov 2018-09-13 22:09:43 +03:00 committed by Noel Grandin
parent 7d6be61a62
commit 87b24ddbba
5 changed files with 52 additions and 125 deletions

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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) );
}

View file

@ -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;
auto ii = std::find(m_vChildren.begin(), m_vChildren.end(), pChild);
if (ii == m_vChildren.end())
return -1;
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;
}
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();