Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi all,

this is a patch we wrote during the libreoffice hackfest 2011 for
sw/source/core/inc/MarkManager.hxx and sw/source/core/doc/docbm.cxx
which improves speed of mailmerge. Bjoern already knows details so he
might be the one to review the patch... The patch could be applied
under the lgpl.

bye,
Christoph Lutz, Landeshauptstadt München
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index b88de10..65afbdc 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -386,6 +386,7 @@ namespace sw { namespace mark
             pMarkBase->SetName(getUniqueMarkName(pMarkBase->GetName()));
 
         // register mark
+        m_aMarkNamesSet.insert(pMarkBase->GetName());
         lcl_InsertMarkSorted(m_vMarks, pMark);
         switch(eType)
         {
@@ -480,8 +481,10 @@ namespace sw { namespace mark
             " - Mark is not in my doc.");
         if(io_pMark->GetName() == rNewName)
             return true;
-        if(findMark(rNewName) != getMarksEnd())
+        if(hasMark(rNewName))
             return false;
+       m_aMarkNamesSet.erase(dynamic_cast< ::sw::mark::MarkBase* >(io_pMark)->GetName());
+       m_aMarkNamesSet.insert(rNewName);
         dynamic_cast< ::sw::mark::MarkBase* >(io_pMark)->SetName(rNewName);
         return true;
     }
@@ -733,6 +736,7 @@ namespace sw { namespace mark
         //it anymore.
         pMark_t xHoldPastErase = *aI;
         m_vMarks.erase(aI);
+        m_aMarkNamesSet.erase(ppMark->get()->GetName());
     }
 
     void MarkManager::deleteMark(const IMark* const pMark)
@@ -766,6 +770,7 @@ namespace sw { namespace mark
     {
         m_vFieldmarks.clear();
         m_vBookmarks.clear();
+        m_aMarkNamesSet.clear();
 #if OSL_DEBUG_LEVEL > 1
         for(iterator_t pBkmk = m_vMarks.begin();
             pBkmk != m_vMarks.end();
@@ -827,13 +832,13 @@ namespace sw { namespace mark
         OSL_ENSURE(rName.getLength(),
             "<MarkManager::getUniqueMarkName(..)>"
             " - a name should be proposed");
-        if(findMark(rName) == getMarksEnd()) return rName;
+        if(!hasMark(rName)) return rName;
         ::rtl::OUStringBuffer sBuf;
         ::rtl::OUString sTmp;
         for(sal_Int32 nCnt = 1; nCnt < SAL_MAX_INT32; nCnt++)
         {
             sTmp = sBuf.append(rName).append(nCnt).makeStringAndClear();
-            if(findMark(sTmp) == getMarksEnd()) break;
+            if(!hasMark(sTmp)) break;
         }
         return sTmp;
     }
@@ -845,6 +850,11 @@ namespace sw { namespace mark
         sort(m_vFieldmarks.begin(), m_vFieldmarks.end(), &lcl_MarkOrderingByStart);
     }
 
+    bool MarkManager::hasMark(const ::rtl::OUString& rName) const
+    {
+        return (m_aMarkNamesSet.find(rName) != m_aMarkNamesSet.end());
+    }
+
 }} // namespace ::sw::mark
 
 
diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx
index 415b8e7..1b43ba4 100644
--- a/sw/source/core/inc/MarkManager.hxx
+++ b/sw/source/core/inc/MarkManager.hxx
@@ -31,6 +31,7 @@
 
 #include <IMark.hxx>
 #include <IDocumentMarkAccess.hxx>
+#include <boost/unordered_set.hpp>
 
 namespace sw { namespace mark
 {
@@ -72,6 +73,7 @@ namespace sw { namespace mark
             virtual const_iterator_t getMarksEnd() const;
             virtual sal_Int32 getMarksCount() const;
             virtual const_iterator_t findMark(const ::rtl::OUString& rName) const;
+            virtual bool hasMark(const ::rtl::OUString& rName) const;
 
             // bookmarks
             virtual const_iterator_t getBookmarksBegin() const;
@@ -92,6 +94,7 @@ namespace sw { namespace mark
             container_t m_vMarks;
             container_t m_vBookmarks;
             container_t m_vFieldmarks;
+            ::boost::unordered_set<rtl::OUString> m_aMarkNamesSet;
             SwDoc * const m_pDoc;
     };
 }}

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.