Revert "i#118224: kill O(n^2) complexity of unique bookmark name creation"

This creates multiple crashes on windows when trying to load writer document
or to save it

This reverts commit e024f61693.
This commit is contained in:
Fridrich Štrba 2011-09-14 16:05:16 +02:00
parent 387620beff
commit 05a66052ae
2 changed files with 4 additions and 33 deletions

View file

@ -390,7 +390,6 @@ namespace sw { namespace mark
pMarkBase->SetName(getUniqueMarkName(pMarkBase->GetName()));
// register mark
m_aMarkNamesSet.insert(pMarkBase->GetName());
lcl_InsertMarkSorted(m_vMarks, pMark);
switch(eType)
{
@ -485,10 +484,8 @@ namespace sw { namespace mark
" - Mark is not in my doc.");
if(io_pMark->GetName() == rNewName)
return true;
if(hasMark(rNewName))
if(findMark(rNewName) != getMarksEnd())
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;
}
@ -740,7 +737,6 @@ 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)
@ -774,7 +770,6 @@ 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();
@ -836,25 +831,14 @@ namespace sw { namespace mark
OSL_ENSURE(rName.getLength(),
"<MarkManager::getUniqueMarkName(..)>"
" - a name should be proposed");
if(!hasMark(rName)) return rName;
if(findMark(rName) == getMarksEnd()) return rName;
::rtl::OUStringBuffer sBuf;
::rtl::OUString sTmp;
// try the name "<rName>XXX" (where XXX is a number starting from 1) unless there is
// a unused name. Due to performance-reasons (especially in mailmerge-Szenarios) there
// is a map m_aMarkBasenameMapUniqueOffset which holds the next possible offset (XXX) for
// rName (so there is no need to test for nCnt-values smaller than the offset).
sal_Int32 nCnt = 1;
MarkBasenameMapUniqueOffset_t::const_iterator aIter = m_aMarkBasenameMapUniqueOffset.find(rName);
if(aIter != m_aMarkBasenameMapUniqueOffset.end()) nCnt = aIter->second;
while(nCnt < SAL_MAX_INT32)
for(sal_Int32 nCnt = 1; nCnt < SAL_MAX_INT32; nCnt++)
{
sTmp = sBuf.append(rName).append(nCnt).makeStringAndClear();
nCnt++;
if(!hasMark(sTmp)) break;
if(findMark(sTmp) == getMarksEnd()) break;
}
m_aMarkBasenameMapUniqueOffset[rName] = nCnt;
return sTmp;
}
@ -865,11 +849,6 @@ 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

View file

@ -31,14 +31,9 @@
#include <IMark.hxx>
#include <IDocumentMarkAccess.hxx>
#include <boost/unordered_set.hpp>
#include <boost/unordered_map.hpp>
namespace sw { namespace mark
{
typedef boost::unordered_map<rtl::OUString, sal_Int32, rtl::OUStringHash> MarkBasenameMapUniqueOffset_t;
class MarkManager
: private ::boost::noncopyable
, virtual public IDocumentMarkAccess
@ -77,7 +72,6 @@ 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;
@ -98,8 +92,6 @@ namespace sw { namespace mark
container_t m_vMarks;
container_t m_vBookmarks;
container_t m_vFieldmarks;
boost::unordered_set<rtl::OUString, rtl::OUStringHash> m_aMarkNamesSet;
mutable MarkBasenameMapUniqueOffset_t m_aMarkBasenameMapUniqueOffset;
SwDoc * const m_pDoc;
};
}}