lotuswordpro/source/filter/lwpdoc.cxx         |   36 ++++++++++++------------
 lotuswordpro/source/filter/lwpfnlayout.cxx    |    6 ++--
 lotuswordpro/source/filter/lwplayout.cxx      |   18 ++++++------
 lotuswordpro/source/filter/lwppagelayout.cxx  |   14 ++++-----
 lotuswordpro/source/filter/lwppara.cxx        |    6 ++--
 lotuswordpro/source/filter/lwppara1.cxx       |    6 ++--
 lotuswordpro/source/filter/lwprowlayout.cxx   |   14 ++++-----
 lotuswordpro/source/filter/lwpstory.cxx       |   27 +++++++++---------
 lotuswordpro/source/filter/lwptablelayout.cxx |   38 +++++++++++++-------------
 9 files changed, 82 insertions(+), 83 deletions(-)

New commits:
commit 3059d56c9d91b7450e2229b2baee0ddc2cf8fa0d
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Sat Oct 16 20:25:44 2021 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sun Oct 17 22:02:47 2021 +0200

    just do one lookup for loop detection
    
    Change-Id: I2b20c15f2e3ec3c4a23d78f6fab85db763fce033
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123705
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/lotuswordpro/source/filter/lwpdoc.cxx 
b/lotuswordpro/source/filter/lwpdoc.cxx
index bb9c8810e899..d83b37500d9a 100644
--- a/lotuswordpro/source/filter/lwpdoc.cxx
+++ b/lotuswordpro/source/filter/lwpdoc.cxx
@@ -298,13 +298,13 @@ void LwpDocument::RegisterStylesInPara()
     o3tl::sorted_vector<LwpStory*> aSeen;
     while (xStory.is())
     {
-        aSeen.insert(xStory.get());
+        bool bAlreadySeen = !aSeen.insert(xStory.get()).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
         //Register the child para
         xStory->SetFoundry(m_xOwnedFoundry.get());
         xStory->DoRegisterStyle();
         
xStory.set(dynamic_cast<LwpStory*>(xStory->GetNext().obj(VO_STORY).get()));
-        if (aSeen.find(xStory.get()) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
     }
 }
 /**
@@ -323,12 +323,12 @@ void LwpDocument::RegisterBulletStyles()
     o3tl::sorted_vector<LwpSilverBullet*> aSeen;
     while (pBullet)
     {
-        aSeen.insert(pBullet);
+        bool bAlreadySeen = !aSeen.insert(pBullet).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
         pBullet->SetFoundry(m_xOwnedFoundry.get());
         pBullet->RegisterStyle();
         pBullet = 
dynamic_cast<LwpSilverBullet*>(pBullet->GetNext().obj().get());
-        if (aSeen.find(pBullet) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
     }
 }
 /**
@@ -574,7 +574,9 @@ LwpDocument* LwpDocument::GetLastDivisionWithContents()
         o3tl::sorted_vector<LwpDocument*> aSeen;
         while (pDivision && pDivision != this)
         {
-            aSeen.insert(pDivision);
+            bool bAlreadySeen = !aSeen.insert(pDivision).second;
+            if (bAlreadySeen)
+                throw std::runtime_error("loop in conversion");
             LwpDocument* pContentDivision = 
pDivision->GetLastDivisionWithContents();
             if (pContentDivision)
             {
@@ -582,8 +584,6 @@ LwpDocument* LwpDocument::GetLastDivisionWithContents()
                 break;
             }
             pDivision = pDivision->GetPreviousDivision();
-            if (aSeen.find(pDivision) != aSeen.end())
-                throw std::runtime_error("loop in conversion");
         }
     }
 
@@ -640,12 +640,12 @@ LwpDocument* LwpDocument::GetRootDocument()
     o3tl::sorted_vector<LwpDocument*> aSeen;
     while (pRoot)
     {
-        aSeen.insert(pRoot);
+        bool bAlreadySeen = !aSeen.insert(pRoot).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
         if (!pRoot->IsChildDoc())
             return pRoot;
         pRoot = pRoot->GetParentDivision();
-        if (aSeen.find(pRoot) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
     }
     return nullptr;
 }
@@ -662,13 +662,13 @@ LwpDocument* 
LwpDocument::ImplGetFirstDivisionWithContentsThatIsNotOLE()
     o3tl::sorted_vector<LwpDocument*> aSeen;
     while (pDivision)
     {
-        aSeen.insert(pDivision);
+        bool bAlreadySeen = !aSeen.insert(pDivision).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
         LwpDocument* pContentDivision = 
pDivision->GetFirstDivisionWithContentsThatIsNotOLE();
         if (pContentDivision)
             return pContentDivision;
         pDivision = pDivision->GetNextDivision();
-        if (aSeen.find(pDivision) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
     }
     return nullptr;
 }
@@ -682,12 +682,12 @@ LwpDocument* LwpDocument::GetLastDivisionThatHasEndnote()
     o3tl::sorted_vector<LwpDocument*> aSeen;
     while (pLastDoc)
     {
-        aSeen.insert(pLastDoc);
+        bool bAlreadySeen = !aSeen.insert(pLastDoc).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
         if (pLastDoc->GetEnSuperTableLayout().is())
             return pLastDoc;
         pLastDoc = pLastDoc->GetPreviousDivisionWithContents();
-        if (aSeen.find(pLastDoc) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
     }
     return nullptr;
 }
diff --git a/lotuswordpro/source/filter/lwpfnlayout.cxx 
b/lotuswordpro/source/filter/lwpfnlayout.cxx
index 0cdede0560d4..febf995acffc 100644
--- a/lotuswordpro/source/filter/lwpfnlayout.cxx
+++ b/lotuswordpro/source/filter/lwpfnlayout.cxx
@@ -115,13 +115,13 @@ void LwpFnRowLayout::RegisterStyle()
     o3tl::sorted_vector<LwpCellLayout*> aSeen;
     while (pCellLayout)
     {
-        aSeen.insert(pCellLayout);
+        bool bAlreadySeen = !aSeen.insert(pCellLayout).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
         pCellLayout->SetFoundry(m_pFoundry);
         pCellLayout->RegisterStyle();
         pCellID = &pCellLayout->GetNext();
         pCellLayout = dynamic_cast<LwpCellLayout*>(pCellID->obj().get());
-        if (aSeen.find(pCellLayout) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
     }
 }
 
diff --git a/lotuswordpro/source/filter/lwplayout.cxx 
b/lotuswordpro/source/filter/lwplayout.cxx
index 29d663602f8b..881b35d8dc48 100644
--- a/lotuswordpro/source/filter/lwplayout.cxx
+++ b/lotuswordpro/source/filter/lwplayout.cxx
@@ -492,15 +492,15 @@ void LwpHeadLayout::RegisterStyle()
     o3tl::sorted_vector<LwpVirtualLayout*> aSeen;
     while (xLayout.is())
     {
-        aSeen.insert(xLayout.get());
+        bool bAlreadySeen = !aSeen.insert(xLayout.get()).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
         xLayout->SetFoundry(m_pFoundry);
         //if the layout is relative to para, the layout will be registered in 
para
         if (!xLayout->IsRelativeAnchored())
             xLayout->DoRegisterStyle();
         rtl::Reference<LwpVirtualLayout> xNext(
             dynamic_cast<LwpVirtualLayout*>(xLayout->GetNext().obj().get()));
-        if (aSeen.find(xNext.get()) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
         xLayout = xNext;
     }
 }
@@ -516,14 +516,14 @@ rtl::Reference<LwpVirtualLayout> 
LwpHeadLayout::FindEnSuperTableLayout()
     o3tl::sorted_vector<LwpVirtualLayout*> aSeen;
     while (xLayout)
     {
-        aSeen.insert(xLayout.get());
+        bool bAlreadySeen = !aSeen.insert(xLayout.get()).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
         if (xLayout->GetLayoutType() == LWP_ENDNOTE_SUPERTABLE_LAYOUT)
         {
             return xLayout;
         }
         
xLayout.set(dynamic_cast<LwpVirtualLayout*>(xLayout->GetNext().obj().get()));
-        if (aSeen.find(xLayout.get()) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
     }
     return rtl::Reference<LwpVirtualLayout>();
 }
@@ -1362,15 +1362,15 @@ rtl::Reference<LwpVirtualLayout> 
LwpMiddleLayout::GetWaterMarkLayout()
     o3tl::sorted_vector<LwpVirtualLayout*> aSeen;
     while (xLay.is())
     {
-        aSeen.insert(xLay.get());
+        bool bAlreadySeen = !aSeen.insert(xLay.get()).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
         if (xLay->IsForWaterMark())
         {
             return xLay;
         }
         rtl::Reference<LwpVirtualLayout> xNext(
             dynamic_cast<LwpVirtualLayout*>(xLay->GetNext().obj().get()));
-        if (aSeen.find(xNext.get()) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
         xLay = xNext;
     }
     return rtl::Reference<LwpVirtualLayout>();
diff --git a/lotuswordpro/source/filter/lwppagelayout.cxx 
b/lotuswordpro/source/filter/lwppagelayout.cxx
index 735a0791c2e2..822d82866de2 100644
--- a/lotuswordpro/source/filter/lwppagelayout.cxx
+++ b/lotuswordpro/source/filter/lwppagelayout.cxx
@@ -552,7 +552,9 @@ LwpPageLayout* LwpPageLayout::GetOddChildLayout()
         o3tl::sorted_vector<LwpVirtualLayout*> aSeen;
         while (xLay.is())
         {
-            aSeen.insert(xLay.get());
+            bool bAlreadySeen = !aSeen.insert(xLay.get()).second;
+            if (bAlreadySeen)
+                throw std::runtime_error("loop in conversion");
 
             if (xLay->GetLayoutType() == LWP_PAGE_LAYOUT)
             {
@@ -564,9 +566,6 @@ LwpPageLayout* LwpPageLayout::GetOddChildLayout()
                 }
             }
             
xLay.set(dynamic_cast<LwpVirtualLayout*>(xLay->GetNext().obj().get()));
-
-            if (aSeen.find(xLay.get()) != aSeen.end())
-                throw std::runtime_error("loop in conversion");
         }
     }
     return nullptr;
@@ -610,7 +609,9 @@ sal_Int32 LwpPageLayout::GetPageNumber(sal_uInt16 
nLayoutNumber)
     o3tl::sorted_vector<LwpPageHint*> aSeen;
     while (pPageHint)
     {
-        aSeen.insert(pPageHint);
+        bool bAlreadySeen = !aSeen.insert(pPageHint).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
 
         if (GetObjectID() == pPageHint->GetPageLayoutID())
         {
@@ -640,9 +641,6 @@ sal_Int32 LwpPageLayout::GetPageNumber(sal_uInt16 
nLayoutNumber)
         }
 
         pPageHint = 
dynamic_cast<LwpPageHint*>(pPageHint->GetNext().obj().get());
-
-        if (aSeen.find(pPageHint) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
     }
     if (nPageNumber >= 0)
     {
diff --git a/lotuswordpro/source/filter/lwppara.cxx 
b/lotuswordpro/source/filter/lwppara.cxx
index 2a7f3843a5c5..50a1cd96eab1 100644
--- a/lotuswordpro/source/filter/lwppara.cxx
+++ b/lotuswordpro/source/filter/lwppara.cxx
@@ -497,7 +497,9 @@ void LwpPara::RegisterStyle()
                     o3tl::sorted_vector<LwpPara*> aSeen;
                     while(true)
                     {
-                        aSeen.insert(pPara);
+                        bool bAlreadySeen = !aSeen.insert(pPara).second;
+                        if (bAlreadySeen)
+                            throw std::runtime_error("loop in conversion");
                         LwpSilverBullet* pParaSilverBullet = 
pPara->GetSilverBullet();
                         pNumbering = pPara->GetParaNumbering();
 
@@ -587,8 +589,6 @@ void LwpPara::RegisterStyle()
                             }
                         }
                         pPara = pPrePara;
-                        if (aSeen.find(pPara) != aSeen.end())
-                            throw std::runtime_error("loop in conversion");
                     }
                     nNum = nNum ? nNum : 1;
 
diff --git a/lotuswordpro/source/filter/lwppara1.cxx 
b/lotuswordpro/source/filter/lwppara1.cxx
index 621a0bdac6b3..cfd801cc07f4 100644
--- a/lotuswordpro/source/filter/lwppara1.cxx
+++ b/lotuswordpro/source/filter/lwppara1.cxx
@@ -143,13 +143,13 @@ LwpPara* LwpPara::GetParent()
         o3tl::sorted_vector<LwpPara*> aSeen;
         while (pPara)
         {
-            aSeen.insert(pPara);
+            bool bAlreadySeen = !aSeen.insert(pPara).second;
+            if (bAlreadySeen)
+                throw std::runtime_error("loop in conversion");
             otherlevel = pPara->GetLevel();
             if ((otherlevel < level) || (otherlevel && (level == 0)))
                 return pPara;
             pPara = dynamic_cast<LwpPara*>(pPara->GetPrevious().obj().get());
-            if (aSeen.find(pPara) != aSeen.end())
-                throw std::runtime_error("loop in conversion");
         }
     }
     return nullptr;
diff --git a/lotuswordpro/source/filter/lwprowlayout.cxx 
b/lotuswordpro/source/filter/lwprowlayout.cxx
index 3b06b64efb67..b5583d19e6d4 100644
--- a/lotuswordpro/source/filter/lwprowlayout.cxx
+++ b/lotuswordpro/source/filter/lwprowlayout.cxx
@@ -97,13 +97,14 @@ void LwpRowLayout::SetRowMap()
     o3tl::sorted_vector<LwpCellLayout*> aSeen;
     while(pCellLayout)
     {
-        aSeen.insert(pCellLayout);
+        bool bAlreadySeen = !aSeen.insert(pCellLayout).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
+
         pCellLayout->SetCellMap();
 
         pCellID = &pCellLayout->GetNext();
         pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj().get());
-        if (aSeen.find(pCellLayout) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
     }
 }
 /**
@@ -141,15 +142,14 @@ void LwpRowLayout::RegisterStyle()
     o3tl::sorted_vector<LwpCellLayout*> aSeen;
     while (pCellLayout)
     {
-        aSeen.insert(pCellLayout);
+        bool bAlreadySeen = !aSeen.insert(pCellLayout).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
 
         pCellLayout->SetFoundry(m_pFoundry);
         pCellLayout->RegisterStyle();
         pCellID = &pCellLayout->GetNext();
         pCellLayout = dynamic_cast<LwpCellLayout *>(pCellID->obj().get());
-
-        if (aSeen.find(pCellLayout) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
     }
 
 }
diff --git a/lotuswordpro/source/filter/lwpstory.cxx 
b/lotuswordpro/source/filter/lwpstory.cxx
index 0b15e79a633e..acc0beebcf4b 100644
--- a/lotuswordpro/source/filter/lwpstory.cxx
+++ b/lotuswordpro/source/filter/lwpstory.cxx
@@ -105,18 +105,19 @@ void LwpStory::XFConvert(XFContentContainer* pCont)
     //process para list
     XFContentContainer* pParaCont = pCont;
     rtl::Reference<LwpPara> 
xPara(dynamic_cast<LwpPara*>(GetFirstPara().obj().get()));
-    o3tl::sorted_vector<LwpPara*> aConverted;
+    o3tl::sorted_vector<LwpPara*> aSeen;
     while (xPara.is())
     {
+        bool bAlreadySeen = !aSeen.insert(xPara.get()).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
+
         xPara->SetFoundry(m_pFoundry);
         xPara->XFConvert(pParaCont);
-        aConverted.insert(xPara.get());
 
         //Get the xfcontainer for the next para
         pParaCont = xPara->GetXFContainer();
         rtl::Reference<LwpPara> 
xNext(dynamic_cast<LwpPara*>(xPara->GetNext().obj().get()));
-        if (aConverted.find(xNext.get()) != aConverted.end())
-            throw std::runtime_error("loop in conversion");
         xPara = xNext;
     }
 
@@ -143,12 +144,12 @@ void LwpStory::RegisterStyle()
     o3tl::sorted_vector<LwpPara*> aSeen;
     while (xPara.is())
     {
-        aSeen.insert(xPara.get());
+        bool bAlreadySeen = !aSeen.insert(xPara.get()).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in register style");
         xPara->SetFoundry(m_pFoundry);
         xPara->DoRegisterStyle();
         xPara.set(dynamic_cast<LwpPara*>(xPara->GetNext().obj().get()));
-        if (aSeen.find(xPara.get()) != aSeen.end())
-            throw std::runtime_error("loop in register style");
     }
 }
 
@@ -326,7 +327,9 @@ void LwpStory::XFConvertFrameInPage(XFContentContainer* 
pCont)
         o3tl::sorted_vector<LwpVirtualLayout*> aSeen;
         while (xFrameLayout.is())
         {
-            aSeen.insert(xFrameLayout.get());
+            bool bAlreadySeen = !aSeen.insert(xFrameLayout.get()).second;
+            if (bAlreadySeen)
+                throw std::runtime_error("loop in conversion");
             if( xFrameLayout->IsAnchorPage()
                 && (xFrameLayout->IsFrame()
                     || xFrameLayout->IsSuperTable()
@@ -335,8 +338,6 @@ void LwpStory::XFConvertFrameInPage(XFContentContainer* 
pCont)
                 xFrameLayout->DoXFConvert(pCont);
             }
             
xFrameLayout.set(dynamic_cast<LwpVirtualLayout*>(xFrameLayout->GetNext().obj().get()));
-            if (aSeen.find(xFrameLayout.get()) != aSeen.end())
-                throw std::runtime_error("loop in conversion");
         }
         xLayout = GetLayout(xLayout.get());
     }
@@ -353,14 +354,14 @@ void LwpStory::XFConvertFrameInFrame(XFContentContainer* 
pCont)
         o3tl::sorted_vector<LwpVirtualLayout*> aSeen;
         while (xFrameLayout.is())
         {
-            aSeen.insert(xFrameLayout.get());
+            bool bAlreadySeen = !aSeen.insert(xFrameLayout.get()).second;
+            if (bAlreadySeen)
+                throw std::runtime_error("loop in register style");
             if (xFrameLayout->IsAnchorFrame())
             {
                 xFrameLayout->DoXFConvert(pCont);
             }
             
xFrameLayout.set(dynamic_cast<LwpVirtualLayout*>(xFrameLayout->GetNext().obj().get()));
-            if (aSeen.find(xFrameLayout.get()) != aSeen.end())
-                throw std::runtime_error("loop in register style");
         }
         xLayout = GetLayout(xLayout.get());
     }
diff --git a/lotuswordpro/source/filter/lwptablelayout.cxx 
b/lotuswordpro/source/filter/lwptablelayout.cxx
index 2a72e1155cb0..70a387781394 100644
--- a/lotuswordpro/source/filter/lwptablelayout.cxx
+++ b/lotuswordpro/source/filter/lwptablelayout.cxx
@@ -235,7 +235,9 @@ double LwpSuperTableLayout::GetTableWidth()
             o3tl::sorted_vector<LwpColumnLayout*> aSeen;
             while (pColumnLayout)
             {
-                aSeen.insert(pColumnLayout);
+                bool bAlreadySeen = !aSeen.insert(pColumnLayout).second;
+                if (bAlreadySeen)
+                    throw std::runtime_error("loop in conversion");
                 if(pColumnLayout->GetColumnID() == i)
                 {
                     dColumnWidth = pColumnLayout->GetWidth();
@@ -243,8 +245,6 @@ double LwpSuperTableLayout::GetTableWidth()
                 }
                 pColumnID = &pColumnLayout->GetNext();
                 pColumnLayout = dynamic_cast<LwpColumnLayout 
*>(pColumnID->obj().get());
-                if (aSeen.find(pColumnLayout) != aSeen.end())
-                    throw std::runtime_error("loop in conversion");
             }
             dWidth += dColumnWidth;
         }
@@ -456,7 +456,9 @@ void LwpTableLayout::TraverseTable()
     o3tl::sorted_vector<LwpRowLayout*> aSeen;
     while (pRowLayout)
     {
-        aSeen.insert(pRowLayout);
+        bool bAlreadySeen = !aSeen.insert(pRowLayout).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
 
         pRowLayout->SetRowMap();
 
@@ -467,8 +469,6 @@ void LwpTableLayout::TraverseTable()
 
         pRowID = &pRowLayout->GetNext();
         pRowLayout = dynamic_cast<LwpRowLayout *>(pRowID->obj().get());
-        if (aSeen.find(pRowLayout) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
     }
 }
 
@@ -574,7 +574,9 @@ void LwpTableLayout::RegisterColumns()
     o3tl::sorted_vector<LwpColumnLayout*> aSeen;
     while (pColumnLayout)
     {
-        aSeen.insert(pColumnLayout);
+        bool bAlreadySeen = !aSeen.insert(pColumnLayout).second;
+        if (bAlreadySeen)
+            throw std::runtime_error("loop in conversion");
 
         auto nColId = pColumnLayout->GetColumnID();
         if (nColId >= nCols)
@@ -591,9 +593,6 @@ void LwpTableLayout::RegisterColumns()
 
         pColumnID = &pColumnLayout->GetNext();
         pColumnLayout = dynamic_cast<LwpColumnLayout 
*>(pColumnID->obj().get());
-
-        if (aSeen.find(pColumnLayout) != aSeen.end())
-            throw std::runtime_error("loop in conversion");
     }
 
     // if all columns are not justifiable, the rightmost column will be 
changed to justifiable
@@ -1147,15 +1146,15 @@ void LwpTableLayout::PutCellVals(LwpFoundry* pFoundry, 
LwpObjectID aTableID)
         o3tl::sorted_vector<LwpTableRange*> aTableSeen;
         while (pTableRange)
         {
-            aTableSeen.insert(pTableRange);
+            bool bAlreadySeenTable = !aTableSeen.insert(pTableRange).second;
+            if (bAlreadySeenTable)
+                throw std::runtime_error("loop in conversion");
             LwpObjectID aID = pTableRange->GetTableID();
             if (aID == aTableID)
             {
                 break;
             }
             pTableRange = pTableRange->GetNext();
-            if (aTableSeen.find(pTableRange) != aTableSeen.end())
-                throw std::runtime_error("loop in conversion");
         }
 
         if (!pTableRange)
@@ -1176,7 +1175,9 @@ void LwpTableLayout::PutCellVals(LwpFoundry* pFoundry, 
LwpObjectID aTableID)
         o3tl::sorted_vector<LwpRowList*> aOuterSeen;
         while (pRowList)
         {
-            aOuterSeen.insert(pRowList);
+            bool bAlreadySeenOuter = !aOuterSeen.insert(pRowList).second;
+            if (bAlreadySeenOuter)
+                throw std::runtime_error("loop in conversion");
             sal_uInt16 nRowID =  pRowList->GetRowID();
             {
                 LwpCellList* pCellList = 
dynamic_cast<LwpCellList*>(pRowList->GetChildHeadID().obj().get());
@@ -1184,7 +1185,10 @@ void LwpTableLayout::PutCellVals(LwpFoundry* pFoundry, 
LwpObjectID aTableID)
                 o3tl::sorted_vector<LwpCellList*> aSeen;
                 while (pCellList)
                 {
-                    aSeen.insert(pCellList);
+                    bool bAlreadySeen = !aSeen.insert(pCellList).second;
+                    if (bAlreadySeen)
+                        throw std::runtime_error("loop in conversion");
+
                     {//put cell
                         sal_uInt16 nColID = pCellList->GetColumnID();
 
@@ -1201,13 +1205,9 @@ void LwpTableLayout::PutCellVals(LwpFoundry* pFoundry, 
LwpObjectID aTableID)
 
                     }
                     pCellList = 
dynamic_cast<LwpCellList*>(pCellList->GetNextID().obj().get());
-                    if (aSeen.find(pCellList) != aSeen.end())
-                        throw std::runtime_error("loop in conversion");
                 }
             }
             pRowList = 
dynamic_cast<LwpRowList*>(pRowList->GetNextID().obj().get());
-            if (aOuterSeen.find(pRowList) != aOuterSeen.end())
-                throw std::runtime_error("loop in conversion");
         }
 
     }catch (...) {

Reply via email to