From 8d11531565d746dd6a7938c4f3536ad34698092d Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Thu, 26 Dec 2013 23:15:24 +0100 Subject: Copy mail merge source instead of loading Currently a mail merge loads the styles from the source document and also loads the original source per mail merge dataset. The new code is based on the MergeDocuments function and swaps the loading with an internal document copy to improve mail merge throughtput. For a mail merge with 99 datasets and a two pages document, callgrind shows an improvement from routhly 44 to 31 billion inclusive instructions for the single SwXMailMerge::execute call. Change-Id: I6929ba371f81c3ea1f26ea3a25e7751bc53256e3 Reviewed-on: https://gerrit.libreoffice.org/7433 Tested-by: Michael Stahl Reviewed-by: Michael Stahl --- sw/source/ui/dbui/dbmgr.cxx | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/sw/source/ui/dbui/dbmgr.cxx b/sw/source/ui/dbui/dbmgr.cxx index e9e0319e909e..63d70d126f4b 100644 --- a/sw/source/ui/dbui/dbmgr.cxx +++ b/sw/source/ui/dbui/dbmgr.cxx @@ -869,11 +869,8 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell, pSfxDispatcher->Execute( pSourceDocSh->HasName() ? SID_SAVEDOC : SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD); if( !pSourceDocSh->IsModified() ) { - SfxMedium* pOrig = pSourceDocSh->GetMedium(); - OUString sSourceDocumentURL(pOrig->GetURLObject().GetMainURL( INetURLObject::NO_DECODE )); - const SfxFilter* pSfxFlt = SwIoSystem::GetFileFilter( - sSourceDocumentURL, ::aEmptyOUStr ); - const SfxFilter* pStoreToFilter = pSfxFlt; + const SfxFilter* pStoreToFilter = SwIoSystem::GetFileFilter( + pSourceDocSh->GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), ::aEmptyOUStr ); SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer(); const OUString* pStoreToFilterOptions = 0; @@ -922,14 +919,7 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell, pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() ); pTargetShell = pTargetView->GetWrtShellPtr(); //copy the styles from the source to the target document - SwgReaderOption aOpt; - aOpt.SetTxtFmts( sal_True ); - aOpt.SetFrmFmts( sal_True ); - aOpt.SetPageDescs( sal_True ); - aOpt.SetNumRules( sal_True ); - aOpt.SetMerge( sal_False ); - pTargetView->GetDocShell()->LoadStylesFromFile( - sSourceDocumentURL, aOpt, sal_True ); + pTargetView->GetDocShell()->_LoadStyles( *pSourceDocSh, sal_True ); //determine the page style and number used at the start of the source document pSourceShell->SttEndDoc(sal_True); nStartingPageNo = pSourceShell->GetVirtPageNum(); @@ -1026,13 +1016,19 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell, for (sal_uInt16 i = 0; i < 25; i++) Application::Reschedule(); - // Create and save new document // The SfxObjectShell will be closed explicitly later but it is more safe to use SfxObjectShellLock here - SfxObjectShellLock xWorkDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL )); - SfxMedium* pWorkMed = new SfxMedium( sSourceDocumentURL, STREAM_STD_READ ); - pWorkMed->SetFilter( pSfxFlt ); + SfxObjectShellLock xWorkDocSh; + // copy the source document + if( 1 == nDocNo && (bAsSingleFile || rMergeDescriptor.bCreateSingleFile) ) + { + uno::Reference< util::XCloneable > xClone( pSourceDocSh->GetModel(), uno::UNO_QUERY); + uno::Reference< lang::XUnoTunnel > xWorkDocShell( xClone->createClone(), uno::UNO_QUERY); + SwXTextDocument* pWorkModel = reinterpret_cast(xWorkDocShell->getSomething(SwXTextDocument::getUnoTunnelId())); + xWorkDocSh = pWorkModel->GetDocShell(); + } + else + xWorkDocSh = pSourceDocSh->GetDoc()->CreateCopy( true ); - if (xWorkDocSh->DoLoad(pWorkMed)) { //create a view frame for the document SfxViewFrame* pWorkFrame = SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 ); -- cgit