Kaydet (Commit) bb00a009 authored tarafından Luboš Luňák's avatar Luboš Luňák

do not bother with nice unique names during mailmerge

When using a single document for all the generating MM documents, there can
be a significant number of sections/etc. , enough to make searching them
all in order to find a next nice unique name take a noticeable time. Since
it's very unlikely anybody will ever care about nice names after mailmerge,
just get some unique name in a fast way.

Change-Id: Id6b8d39a67529984cb93bb369f2c6eab401f1799
üst f1fb3fae
......@@ -52,6 +52,7 @@
#include <viscrs.hxx>
#include <edimp.hxx>
#include <stdio.h>
#include <tools/datetimeutils.hxx>
using namespace ::boost;
using namespace ::sw::mark;
......@@ -1069,6 +1070,14 @@ namespace sw { namespace mark
{
OSL_ENSURE(rName.getLength(),
"<MarkManager::getUniqueMarkName(..)> - a name should be proposed");
if( m_pDoc->IsInMailMerge())
{
OUString newName = rName + "MailMergeMark"
+ OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+ OUString::number( m_vAllMarks.size() + 1 );
return newName;
}
if ( findMark(rName) == getAllMarksEnd() )
{
return rName;
......@@ -1076,13 +1085,9 @@ namespace sw { namespace mark
OUStringBuffer sBuf;
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;
// Try the name "<rName>XXX", where XXX is a number. Start the number at the existing count rather than 1
// in order to increase the chance that already the first one will not exist.
sal_Int32 nCnt = m_vAllMarks.size() + 1;
while(nCnt < SAL_MAX_INT32)
{
sTmp = sBuf.append(rName).append(nCnt).makeStringAndClear();
......@@ -1092,8 +1097,6 @@ namespace sw { namespace mark
break;
}
}
m_aMarkBasenameMapUniqueOffset[rName] = nCnt;
return sTmp;
}
......
......@@ -94,6 +94,7 @@
#include <pagedesc.hxx>
#include <PostItMgr.hxx>
#include <comcore.hrc>
#include <tools/datetimeutils.hxx>
#include <unoframe.hxx>
......@@ -1287,6 +1288,14 @@ IMPL_STATIC_LINK( SwDoc, BackgroundDone, SvxBrushItem*, EMPTYARG )
static OUString lcl_GetUniqueFlyName( const SwDoc* pDoc, sal_uInt16 nDefStrId )
{
if( pDoc->IsInMailMerge())
{
OUString newName = "MailMergeFly"
+ OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+ OUString::number( pDoc->GetSpzFrmFmts()->size() + 1 );
return newName;
}
ResId aId( nDefStrId, *pSwResMgr );
OUString aName( aId );
sal_Int32 nNmLen = aName.getLength();
......
......@@ -55,6 +55,7 @@
#include <list.hxx>
#include <switerator.hxx>
#include <comphelper/string.hxx>
#include <tools/datetimeutils.hxx>
#include <cstdlib>
#include <map>
......@@ -2185,6 +2186,16 @@ sal_uInt16 SwDoc::MakeNumRule( const OUString &rName,
OUString SwDoc::GetUniqueNumRuleName( const OUString* pChkStr, bool bAutoNum ) const
{
if( IsInMailMerge())
{
OUString newName = "MailMergeNumRule"
+ OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+ OUString::number( mpNumRuleTbl->size() + 1 );
if( pChkStr )
newName += *pChkStr;
return newName;
}
OUString aName;
if( bAutoNum )
{
......
......@@ -71,6 +71,7 @@
#include <switerator.hxx>
#include <ToxTextGenerator.hxx>
#include <ToxTabStopTokenHandler.hxx>
#include <tools/datetimeutils.hxx>
#include <boost/make_shared.hpp>
......@@ -609,6 +610,16 @@ const SwTOXType* SwDoc::InsertTOXType( const SwTOXType& rTyp )
OUString SwDoc::GetUniqueTOXBaseName( const SwTOXType& rType,
const OUString& sChkStr ) const
{
if( IsInMailMerge())
{
OUString newName = "MailMergeTOX"
+ OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+ OUString::number( mpSectionFmtTbl->size() + 1 );
if( !sChkStr.isEmpty())
newName += sChkStr;
return newName;
}
bool bUseChkStr = !sChkStr.isEmpty();
const OUString aName( rType.GetTypeName() );
const sal_Int32 nNmLen = aName.getLength();
......
......@@ -58,6 +58,7 @@
#include <txtfrm.hxx>
#include <boost/scoped_ptr.hpp>
#include <ndsect.hxx>
#include <tools/datetimeutils.hxx>
// #i21457# - new implementation of local method <lcl_IsInSameTblBox(..)>.
// Method now determines the previous/next on its own. Thus, it can be controlled,
......@@ -1380,6 +1381,16 @@ void SwSectionNode::NodesArrChgd()
OUString SwDoc::GetUniqueSectionName( const OUString* pChkStr ) const
{
if( IsInMailMerge())
{
OUString newName = "MailMergeSection"
+ OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+ OUString::number( mpSectionFmtTbl->size() + 1 );
if( pChkStr )
newName += *pChkStr;
return newName;
}
const OUString aName( ResId( STR_REGION_DEFNAME, *pSwResMgr ) );
sal_uInt16 nNum = 0;
......
......@@ -94,6 +94,7 @@
#include <switerator.hxx>
#include <o3tl/numeric.hxx>
#include <boost/foreach.hpp>
#include <tools/datetimeutils.hxx>
#ifdef DBG_UTIL
#define CHECK_TABLE(t) (t).CheckConsistency();
......@@ -3861,6 +3862,14 @@ bool SwDoc::GetTableAutoFmt( const SwSelBoxes& rBoxes, SwTableAutoFmt& rGet )
OUString SwDoc::GetUniqueTblName() const
{
if( IsInMailMerge())
{
OUString newName = "MailMergeTable"
+ OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+ OUString::number( mpTblFrmFmtTbl->size() + 1 );
return newName;
}
ResId aId( STR_TABLE_DEFNAME, *pSwResMgr );
const OUString aName( aId );
......
......@@ -27,7 +27,6 @@
namespace sw {
namespace mark {
typedef boost::unordered_map<OUString, sal_Int32, OUStringHash> MarkBasenameMapUniqueOffset_t;
class MarkManager
: private ::boost::noncopyable
......@@ -111,7 +110,6 @@ namespace sw {
container_t m_vFieldmarks;
boost::unordered_set<OUString, OUStringHash> m_aMarkNamesSet;
mutable MarkBasenameMapUniqueOffset_t m_aMarkBasenameMapUniqueOffset;
// container for annotation marks
container_t m_vAnnotationMarks;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment