From ea3e718855d804943831db81428fec249b9c7575 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Thu, 6 Jul 2017 14:13:12 +0200 Subject: sw: convert SwNumberTree::IsSane to assert() and simplify Change-Id: Ib2087a53d2a22f5fdafa5c3d0d058dd0ad8ed643 --- sw/inc/SwNumberTree.hxx | 11 ++--- sw/source/core/SwNumberTree/SwNumberTree.cxx | 72 ++++++++++------------------ 2 files changed, 28 insertions(+), 55 deletions(-) (limited to 'sw') diff --git a/sw/inc/SwNumberTree.hxx b/sw/inc/SwNumberTree.hxx index 3d19458e5b8c..c908eeca490c 100644 --- a/sw/inc/SwNumberTree.hxx +++ b/sw/inc/SwNumberTree.hxx @@ -346,7 +346,7 @@ public: @retval true the structure of this node is sane @retval false else */ - bool IsSane(bool bRecursive) const; + void IsSane(bool bRecursive) const; #endif // DBG_UTIL protected: @@ -391,15 +391,12 @@ protected: virtual void PostRemove() = 0; #ifdef DBG_UTIL - /** - Sanity check with loop detection. + /** Sanity check with loop detection. @param bRecursive descend to children @param rParents vector for recording path - - @retval true this node is sane - @retval false else */ - virtual bool IsSane + */ + virtual void IsSane (bool bRecursive, std::vector rParents) const; #endif // DBG_UTIL diff --git a/sw/source/core/SwNumberTree/SwNumberTree.cxx b/sw/source/core/SwNumberTree/SwNumberTree.cxx index f60f0c0a732b..c606f7b34aea 100644 --- a/sw/source/core/SwNumberTree/SwNumberTree.cxx +++ b/sw/source/core/SwNumberTree/SwNumberTree.cxx @@ -23,6 +23,8 @@ #include #include +#include + using std::vector; using std::find; @@ -385,7 +387,8 @@ void SwNumberTreeNode::MoveGreaterChildren( SwNumberTreeNode& _rCompareNode, } #ifdef DBG_UTIL - SAL_WARN_IF(!IsSane(false) || !_rDestNode.IsSane(true), "sw.core", "insanity"); + IsSane(false); + _rDestNode.IsSane(true); #endif } @@ -433,7 +436,8 @@ void SwNumberTreeNode::MoveChildren(SwNumberTreeNode * pDest) OSL_ENSURE(mChildren.empty(), "MoveChildren failed!"); #ifdef DBG_UTIL - OSL_ENSURE(IsSane(false) && pDest->IsSane(false), "insanity!"); + IsSane(false); + pDest->IsSane(false); #endif } @@ -585,7 +589,7 @@ void SwNumberTreeNode::AddChild( SwNumberTreeNode * pChild, } #ifdef DBG_UTIL - SAL_WARN_IF(!IsSane(false), "sw.core", "insanity"); + IsSane(false); #endif } @@ -678,7 +682,7 @@ void SwNumberTreeNode::RemoveMe() pSavedParent->ClearObsoletePhantoms(); #ifdef DBG_UTIL - SAL_WARN_IF(!IsSane(false), "sw.core", "insanity"); + IsSane(false); #endif } } @@ -857,34 +861,22 @@ SwNumberTreeNode::GetChildCount() const } #ifdef DBG_UTIL -bool SwNumberTreeNode::IsSane(bool bRecursive) const +void SwNumberTreeNode::IsSane(bool bRecursive) const { vector aParents; return IsSane(bRecursive, aParents); } -bool SwNumberTreeNode::IsSane(bool bRecursive, +void SwNumberTreeNode::IsSane(bool bRecursive, vector rParents) const { - bool bResult = true; - tSwNumberTreeChildren::const_iterator aIt; - if (find(rParents.begin(), rParents.end(), this) != rParents.end()) - { - OSL_FAIL(" I'm my own ancestor!"); - - bResult = false; - } + assert(find(rParents.begin(), rParents.end(), this) == rParents.end()); - if (! rParents.empty() && rParents.back() != mpParent) - { - OSL_FAIL(" I'm a bastard!"); - - bResult = false; - } + assert(rParents.empty() || rParents.back() == mpParent); rParents.push_back(this); @@ -895,49 +887,33 @@ bool SwNumberTreeNode::IsSane(bool bRecursive, { if ((*aIt)->IsPhantom()) { - if ((*aIt)->HasOnlyPhantoms()) - { - bResult = false; - } + SAL_WARN_IF((*aIt)->HasOnlyPhantoms(), "sw.core", + "HasOnlyPhantoms: is this an error?"); - if (! bFirst) - { - OSL_FAIL(" found phantom not at first position."); - - bResult = false; - } + assert(bFirst && "found phantom not at first position."); } - if ((*aIt)->mpParent != (SwNumberTreeNode *) this) - { - OSL_FAIL("found a bastard"); - - bResult = false; - } + assert((*aIt)->mpParent == this); if (mpParent) { - if (!(*aIt)->IsPhantom() && (*aIt)->LessThan(*this)) - { - OSL_FAIL(" found child less than me"); - - bResult = false; - } + assert((*aIt)->IsPhantom() || !(*aIt)->LessThan(*this)); } } else { - OSL_FAIL("found child that is NULL"); - bResult = false; + assert(!"found child that is NULL"); } - if (bRecursive) - bResult = (*aIt)->IsSane(bRecursive, rParents) && bResult; + if (bRecursive) + { + (*aIt)->IsSane(bRecursive, rParents); + } + + bFirst = false; } rParents.pop_back(); - - return bResult; } #endif // DBG_UTIL -- cgit