[Libreoffice-commits] core.git: Branch 'private/jmux/indexed-pagedescs' - 122 commits - avmedia/source bin/lo-all-static-libs bridges/inc bridges/source chart2/qa chart2/source codemaker/source compilerplugins/clang config_host.mk.in configure.ac connectivity/source cui/source dbaccess/source desktop/Library_deploymentgui.mk desktop/source desktop/uiconfig desktop/UIConfig_deployment.mk dictionaries download.lst external/apache-commons external/coinmp external/libgltf external/python3 extras/source filter/source formula/source i18nlangtag/qa i18nlangtag/source include/codemaker include/formula include/i18nlangtag include/o3tl include/osl include/sal include/sfx2 include/svx include/tools include/vcl o3tl/qa officecfg/registry oox/source package/source RepositoryExternal.mk sal/cppunittester sal/osl sal/util sc/inc scripting/workben sc/source sdext/Library_pdfimport.mk sdext/source sd/source sfx2/source slideshow/Library_OGLTrans.mk slideshow/source stoc/source svl/source svtools/source svx/inc sv x/source swext/Extension_wiki-publisher.mk sw/inc sw/qa sw/source sw/uiconfig tools/source ucb/source unotools/source uui/source vcl/inc vcl/osx vcl/source vcl/unx writerfilter/source xmloff/source
Jan-Marek Glogowski
glogow at fbihome.de
Wed May 21 08:20:01 PDT 2014
Rebased ref, commits from common ancestor:
commit 8bd3c5772167effec20b210be905e628145a7bd5
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date: Fri May 16 23:42:32 2014 +0200
Convert SwPageDescs to a o3tl::sorted_vector
Originally I planned to use a boost::container::flat_map, but there
seem to be no way to directly access the indexed vector.
And since this already needs the "first item is default" special
handling, o3tl::sorted_vector is used with the offset.
Change-Id: Idfb79af8ddfd5f5e2e6ca312b46d30e3ddc166d9
diff --git a/sw/inc/pagedesc.hxx b/sw/inc/pagedesc.hxx
index 02a68e9..a853ba4 100644
--- a/sw/inc/pagedesc.hxx
+++ b/sw/inc/pagedesc.hxx
@@ -26,6 +26,7 @@
#include <frmfmt.hxx>
#include <editeng/numitem.hxx>
#include <editeng/borderline.hxx>
+#include <o3tl/sorted_vector.hxx>
#include "poolfmt.hxx"
class SfxPoolItem;
@@ -347,21 +348,23 @@ public:
operator SwPageDesc() const; // #i7983#
};
-typedef std::vector<SwPageDesc*> SwPageDescsBase;
+struct CompareSwPageDescs
+{
+ bool operator()(OUString const& lhs, SwPageDesc* const& rhs) const;
+ bool operator()(SwPageDesc* const& lhs, OUString const& rhs) const;
+ bool operator()(SwPageDesc* const& lhs, SwPageDesc* const& rhs) const;
+};
+
+typedef o3tl::sorted_vector<SwPageDesc*, CompareSwPageDescs> SwPageDescsBase;
#define RES_POOLPAGE_SIZE (RES_POOLPAGE_END - RES_POOLPAGE_BEGIN)
// Mimics o3tl::sorted_vector interface
-class SwPageDescs : private SwPageDescsBase
+class SwPageDescs : public SwPageDescsBase
{
// to update the poolpages array on PoolFmtId change
friend void SwPageDesc::SetPoolFmtId( sal_uInt16 nId );
-public:
- typedef typename SwPageDescsBase::const_iterator const_iterator;
- typedef typename SwPageDescsBase::size_type size_type;
- typedef typename SwPageDescsBase::value_type value_type;
-
private:
// fast index for pool page resources
value_type poolpages[RES_POOLPAGE_SIZE];
@@ -378,33 +381,16 @@ public:
void DeleteAndDestroyAll();
- using SwPageDescsBase::clear;
- using SwPageDescsBase::empty;
- using SwPageDescsBase::size;
-
std::pair<const_iterator,bool> insert( const value_type& x );
size_type erase( const value_type& x );
void erase( size_type index );
void erase( const_iterator const& position );
- const value_type& front() const { return SwPageDescsBase::front(); }
- const value_type& back() const { return SwPageDescsBase::back(); }
- const value_type& operator[]( size_t index ) const
- { return SwPageDescsBase::operator[]( index ); }
-
const_iterator find( const OUString &name ) const;
const_iterator find( const value_type& x ) const;
- const_iterator begin() const { return SwPageDescsBase::begin(); }
- const_iterator end() const { return SwPageDescsBase::end(); }
-
bool Contains( const value_type& x ) const;
value_type GetPoolPageDesc( sal_uInt16 nId ) const;
-
-private:
- typedef typename SwPageDescsBase::iterator iterator;
- iterator begin_nonconst() { return SwPageDescsBase::begin(); }
- iterator end_nonconst() { return SwPageDescsBase::end(); }
};
#endif // INCLUDED_SW_INC_PAGEDESC_HXX
diff --git a/sw/source/core/layout/pagedesc.cxx b/sw/source/core/layout/pagedesc.cxx
index 8d67fef..3648a01 100644
--- a/sw/source/core/layout/pagedesc.cxx
+++ b/sw/source/core/layout/pagedesc.cxx
@@ -505,10 +505,8 @@ SwPageDescs::~SwPageDescs()
void SwPageDescs::DeleteAndDestroyAll()
{
- for( const_iterator it = begin(); it != end(); ++it )
- delete *it;
memset(poolpages, 0, sizeof(value_type) * RES_POOLPAGE_SIZE);
- clear();
+ SwPageDescsBase::DeleteAndDestroyAll();
}
std::pair<SwPageDescs::const_iterator,bool> SwPageDescs::insert( const value_type& x )
@@ -517,9 +515,8 @@ std::pair<SwPageDescs::const_iterator,bool> SwPageDescs::insert( const value_typ
SAL_WARN_IF(nId != USHRT_MAX && NULL != GetPoolPageDesc( nId ),
"sw", "Inserting already assigned pool ID item!");
- const_iterator const ret = find( x );
- if (ret == end()) {
- SwPageDescsBase::push_back( x );
+ std::pair<SwPageDescs::const_iterator,bool> ret = SwPageDescsBase::insert( x );
+ if (ret.second) {
if (x->list != 0) {
SAL_WARN("sw", "Inserting already assigned item!");
SAL_WARN_IF(x->list != this, "sw",
@@ -528,9 +525,8 @@ std::pair<SwPageDescs::const_iterator,bool> SwPageDescs::insert( const value_typ
x->list = this;
if (nId != USHRT_MAX)
poolpages[ nId - RES_POOLPAGE_BEGIN ] = x;
- return std::make_pair(end() - 1 , true);
}
- return std::make_pair(ret, false);
+ return ret;
}
void SwPageDescs::_erase( const value_type& x )
@@ -546,57 +542,60 @@ void SwPageDescs::_erase( const value_type& x )
SwPageDescs::size_type SwPageDescs::erase( const value_type& x )
{
- const_iterator const ret = find( x );
- if (ret != end()) {
- SwPageDescsBase::erase( begin_nonconst() + (ret - begin()) );
+ size_type ret = SwPageDescsBase::erase( x );
+ if (ret)
_erase( x );
- return 1;
- }
- return 0;
+ return ret;
}
void SwPageDescs::erase( size_type index )
{
- erase( begin_nonconst() + index );
+ erase( begin() + index );
}
void SwPageDescs::erase( const_iterator const& position )
{
_erase( *position );
- SwPageDescsBase::erase( begin_nonconst() + (position - begin()) );
+ SwPageDescsBase::erase( position );
+}
+
+bool CompareSwPageDescs::operator()(OUString const& lhs, SwPageDesc* const& rhs) const
+{
+ return (lhs.compareTo( rhs->GetName() ) < 0);
}
-struct spd_oustring_compare : public std::unary_function<SwPageDesc*, bool>
+bool CompareSwPageDescs::operator()(SwPageDesc* const& lhs, OUString const& rhs) const
{
- spd_oustring_compare(const OUString &_baseline) : baseline(_baseline) {}
- bool operator() (SwPageDesc* const &arg)
- { return (baseline.compareTo( arg->GetName() ) == 0); }
- const OUString baseline;
-};
+ return (lhs->GetName().compareTo( rhs ) < 0);
+}
-struct spd_item_compare : public std::unary_function<SwPageDesc*, bool>
+bool CompareSwPageDescs::operator()(SwPageDesc* const& lhs, SwPageDesc* const& rhs) const
{
- spd_item_compare(const SwPageDesc* _baseline) : baseline(_baseline) {}
- bool operator() (SwPageDesc* const &arg)
- { return (baseline->GetName().compareTo( arg->GetName() ) == 0); }
- const SwPageDesc* baseline;
-};
+ return (lhs->GetName().compareTo( rhs->GetName() ) < 0);
+}
SwPageDescs::const_iterator SwPageDescs::find( const OUString &name ) const
{
- const_iterator const it = std::find_if(
- begin(), end(), spd_oustring_compare( name ) );
+ if (empty())
+ return end();
+
+ const_iterator it = end();
+ if (size() > 1) {
+ it = std::lower_bound( begin() + 1, end(), name, CompareSwPageDescs() );
+ if (it != end() && CompareSwPageDescs()(name, *it))
+ it = end();
+ }
+ if (it == end() && !name.compareTo( (*this)[0]->GetName() ))
+ it = begin();
return it;
}
SwPageDescs::const_iterator SwPageDescs::find( const value_type& x ) const
{
- const_iterator const it = std::find_if(
- begin(), end(), spd_item_compare( x ) );
- return it;
+ return find( x->GetName() );
}
-bool SwPageDescs::Contains( const SwPageDescs::value_type& x ) const
+bool SwPageDescs::Contains( const value_type& x ) const
{
return (x->list == this);
}
commit 2174ac499589001b6314bbf14f4b524903de27af
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date: Mon May 12 18:55:58 2014 +0200
Fixup vector stuff (catchall)
Fixup many occations of broken vector => sorted_vector stuff and
duplicated code.
This drops a simple optimization from the ww8 filter. I'm not
sure it's worth just to register and update the new styles.
Change-Id: Ia10a5672e882799ee0cb7f14382558f836bc1128
diff --git a/dictionaries b/dictionaries
index b312442..117686e 160000
--- a/dictionaries
+++ b/dictionaries
@@ -1 +1 @@
-Subproject commit b31244205066114f5721beef118be7f9e518cd22
+Subproject commit 117686ef79d5a2a42e328dcef8af3969af933700
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index a92951e8..bd2d755 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1286,6 +1286,9 @@ public:
sal_uInt16* pPos = 0 ) const;
SwPageDesc* FindPageDescByName( const OUString& rName,
sal_uInt16* pPos = 0 );
+ SwPageDesc* FindPageDescByPoolId( sal_uInt16 nPoolId );
+ bool ContainsPageDesc( const SwPageDesc* ) const;
+ bool ContainsPageDesc( const SwPageDesc& ) const;
/** Copy the complete PageDesc - beyond document and "deep"!
Optionally copying of PoolFmtId, -HlpId can be prevented. */
@@ -1303,8 +1306,10 @@ public:
{ CopyPageDescHeaderFooterImpl( false, rSrcFmt, rDestFmt ); }
// For Reader
+ void ChgPageDescP( const SwPageDesc &, SwPageDesc *pDesc = NULL );
void ChgPageDesc( const OUString & rName, const SwPageDesc& );
void ChgPageDesc( sal_uInt16 i, const SwPageDesc& );
+ void DelPageDescP( SwPageDesc *pDel, bool bBroadcast = false );
void DelPageDesc( const OUString & rName, bool bBroadcast = false);
void DelPageDesc( sal_uInt16 i, bool bBroadcast = false );
void PreDelPageDesc(SwPageDesc * pDel);
diff --git a/sw/inc/fesh.hxx b/sw/inc/fesh.hxx
index 5d23fde..6ddd254 100644
--- a/sw/inc/fesh.hxx
+++ b/sw/inc/fesh.hxx
@@ -553,11 +553,11 @@ public:
sal_uInt16 GetMousePageDesc( const Point &rPt ) const;
sal_uInt16 GetPageDescCnt() const;
SwPageDesc* FindPageDescByName( const OUString& rName,
- bool bGetFromPool = false,
- sal_uInt16* pPos = 0 );
+ bool bGetFromPool = false );
const SwPageDesc& GetPageDesc( sal_uInt16 i ) const;
void ChgPageDesc( sal_uInt16 i, const SwPageDesc& );
+ void ChgPageDescP( const SwPageDesc&, SwPageDesc* = NULL );
/** if inside all selection only one PageDesc, @return this.
Otherwise @return 0 pointer */
const SwPageDesc* GetSelectedPageDescs() const;
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index 80febe1..f9f6c5e 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -187,6 +187,7 @@ bool SwCrsrShell::SetCrsrInHdFt( sal_uInt16 nDescNo, bool bInHeader )
{
bool bRet = false;
SwDoc *pMyDoc = GetDoc();
+ const SwPageDesc* rDesc = NULL;
SET_CURR_SHELL( this );
@@ -195,30 +196,26 @@ bool SwCrsrShell::SetCrsrInHdFt( sal_uInt16 nDescNo, bool bInHeader )
// take the current one
const SwPageFrm* pPage = GetCurrFrm()->FindPageFrm();
if( pPage )
- for( sal_uInt16 i = 0; i < pMyDoc->GetPageDescCnt(); ++i )
- if( pPage->GetPageDesc() == &pMyDoc->GetPageDesc( i ) )
- {
- nDescNo = i;
- break;
- }
+ rDesc = pMyDoc->FindPageDescByName( pPage->GetPageDesc()->GetName(), &nDescNo );
}
+ else
+ if (nDescNo < pMyDoc->GetPageDescCnt())
+ rDesc = &pMyDoc->GetPageDesc( nDescNo );
- if( USHRT_MAX != nDescNo && nDescNo < pMyDoc->GetPageDescCnt() )
+ if( rDesc )
{
// check if the attribute exists
- const SwPageDesc& rDesc = const_cast<const SwDoc *>(pMyDoc)
- ->GetPageDesc( nDescNo );
const SwFmtCntnt* pCnt = 0;
if( bInHeader )
{
// mirrored pages? ignore for now
- const SwFmtHeader& rHd = rDesc.GetMaster().GetHeader();
+ const SwFmtHeader& rHd = rDesc->GetMaster().GetHeader();
if( rHd.GetHeaderFmt() )
pCnt = &rHd.GetHeaderFmt()->GetCntnt();
}
else
{
- const SwFmtFooter& rFt = rDesc.GetMaster().GetFooter();
+ const SwFmtFooter& rFt = rDesc->GetMaster().GetFooter();
if( rFt.GetFooterFmt() )
pCnt = &rFt.GetFooterFmt()->GetCntnt();
}
diff --git a/sw/source/core/doc/docdesc.cxx b/sw/source/core/doc/docdesc.cxx
index c4d767a..2e7b8f8 100644
--- a/sw/source/core/doc/docdesc.cxx
+++ b/sw/source/core/doc/docdesc.cxx
@@ -323,11 +323,10 @@ void SwDoc::CopyMasterFooter(const SwPageDesc &rChged, const SwFmtFooter &rFoot,
}
}
-void SwDoc::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged )
+void SwDoc::ChgPageDescP( const SwPageDesc &rChged, SwPageDesc *pDesc )
{
- OSL_ENSURE( i < maPageDescs.size(), "PageDescs is out of range." );
-
- SwPageDesc *pDesc = maPageDescs[i];
+ if (!pDesc)
+ pDesc = const_cast<SwPageDesc*>( &rChged );
SwRootFrm* pTmpRoot = GetCurrentLayout();
if (GetIDocumentUndoRedo().DoesUndo())
@@ -498,12 +497,17 @@ void SwDoc::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged )
: pDesc->GetFirstLeft().GetFooter().GetFooterFmt() == pDesc->GetFirstMaster().GetFooter().GetFooterFmt());
}
+void SwDoc::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged )
+{
+ OSL_ENSURE( i < maPageDescs.size(), "PageDescs is out of range." );
+ ChgPageDescP( rChged, maPageDescs[i] );
+}
+
/// All descriptors whose Follow point to the to-be-deleted have to be adapted.
// #i7983#
void SwDoc::PreDelPageDesc(SwPageDesc * pDel)
{
- if (0 == pDel)
- return;
+ OSL_ENSURE( NULL != pDel, "PageDesc pointer is invalid." );
// mba: test iteration as clients are removed while iteration
SwPageDescHint aHint( maPageDescs[0] );
@@ -561,14 +565,10 @@ void SwDoc::BroadcastStyleOperation(const OUString& rName, SfxStyleFamily eFamil
}
}
-void SwDoc::DelPageDesc( sal_uInt16 i, bool bBroadcast )
+void SwDoc::DelPageDescP( SwPageDesc *pDel, bool bBroadcast )
{
- OSL_ENSURE( i < maPageDescs.size(), "PageDescs is out of range." );
- OSL_ENSURE( i != 0, "You cannot delete the default Pagedesc.");
- if ( i == 0 )
- return;
-
- SwPageDesc *pDel = maPageDescs[i];
+ OSL_ENSURE( pDel != NULL, "Don't try to delete a NULL pointer." );
+ OSL_ENSURE( pDel != maPageDescs[0], "You cannot delete the default Pagedesc." );
if (bBroadcast)
BroadcastStyleOperation(pDel->GetName(), SFX_STYLE_FAMILY_PAGE,
@@ -582,11 +582,17 @@ void SwDoc::DelPageDesc( sal_uInt16 i, bool bBroadcast )
PreDelPageDesc(pDel); // #i7983#
- maPageDescs.erase( maPageDescs.begin() + i );
+ maPageDescs.erase( pDel );
delete pDel;
SetModified();
}
+void SwDoc::DelPageDesc( sal_uInt16 i, bool bBroadcast )
+{
+ OSL_ENSURE( i < maPageDescs.size(), "PageDescs is out of range." );
+ DelPageDescP( maPageDescs[ i ], bBroadcast );
+}
+
SwPageDesc* SwDoc::MakePageDesc( const OUString &rName, const SwPageDesc *pCpy,
bool bRegardLanguage, bool bBroadcast)
{
@@ -784,20 +790,33 @@ SwPageDesc* SwDoc::FindPageDescByName( const OUString & rName, sal_uInt16* pPos
return lcl_FindPageDescByName( const_cast <SwPageDescs *>( &maPageDescs ), rName, pPos );
}
-void SwDoc::DelPageDesc( const OUString & rName, bool bBroadcast )
+SwPageDesc* SwDoc::FindPageDescByPoolId( sal_uInt16 nPoolId )
{
- sal_uInt16 nI;
+ return maPageDescs.GetPoolPageDesc( nPoolId );
+}
- if (FindPageDescByName(rName, &nI))
- DelPageDesc(nI, bBroadcast);
+void SwDoc::DelPageDesc( const OUString & rName, bool bBroadcast )
+{
+ SwPageDesc *pd = FindPageDescByName(rName);
+ if (pd)
+ DelPageDescP(pd, bBroadcast);
}
void SwDoc::ChgPageDesc( const OUString & rName, const SwPageDesc & rDesc)
{
- sal_uInt16 nI;
+ SwPageDesc *pd = FindPageDescByName(rName);
+ if (pd)
+ ChgPageDescP(rDesc, pd);
+}
+
+bool SwDoc::ContainsPageDesc( const SwPageDesc *pg ) const
+{
+ return maPageDescs.Contains( const_cast<SwPageDesc*>( pg ) );
+}
- if (FindPageDescByName(rName, &nI))
- ChgPageDesc(nI, rDesc);
+bool SwDoc::ContainsPageDesc( const SwPageDesc &pg ) const
+{
+ return maPageDescs.Contains( const_cast<SwPageDesc*>( &pg ) );
}
/*
diff --git a/sw/source/core/doc/poolfmt.cxx b/sw/source/core/doc/poolfmt.cxx
index 6547569..d2b25d0 100644
--- a/sw/source/core/doc/poolfmt.cxx
+++ b/sw/source/core/doc/poolfmt.cxx
@@ -1458,13 +1458,9 @@ SwPageDesc* SwDoc::GetPageDescFromPool( sal_uInt16 nId, bool bRegardLanguage )
OSL_ENSURE( RES_POOLPAGE_BEGIN <= nId && nId < RES_POOLPAGE_END,
"Wrong AutoFormat Id" );
- for( sal_uInt16 n = 0; n < maPageDescs.size(); ++n )
- {
- if ( nId == maPageDescs[ n ]->GetPoolFmtId() )
- {
- return maPageDescs[ n ];
- }
- }
+ SwPageDesc* ret = maPageDescs.GetPoolPageDesc( nId );
+ if (ret)
+ return ret;
if( RES_POOLPAGE_BEGIN > nId || nId >= RES_POOLPAGE_END )
{
diff --git a/sw/source/core/frmedt/fedesc.cxx b/sw/source/core/frmedt/fedesc.cxx
index 50c7571..735765f 100644
--- a/sw/source/core/frmedt/fedesc.cxx
+++ b/sw/source/core/frmedt/fedesc.cxx
@@ -41,11 +41,7 @@ void SwFEShell::ChgCurPageDesc( const SwPageDesc& rDesc )
#if OSL_DEBUG_LEVEL > 0
// SS does not change PageDesc, but only sets the attibute.
// The Pagedesc should be available in the document
- bool bFound = false;
- for ( sal_uInt16 nTst = 0; nTst < GetPageDescCnt(); ++nTst )
- if ( &rDesc == &GetPageDesc( nTst ) )
- bFound = true;
- OSL_ENSURE( bFound, "ChgCurPageDesc with invalid descriptor." );
+ OSL_ENSURE( GetDoc()->ContainsPageDesc( rDesc ), "ChgCurPageDesc with invalid descriptor." );
#endif
StartAllAction();
@@ -115,24 +111,35 @@ void SwFEShell::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged )
EndAllActionAndCall();
}
+void SwFEShell::ChgPageDescP( const SwPageDesc &rChged, SwPageDesc *pd )
+{
+ StartAllAction();
+ SET_CURR_SHELL( this );
+ //Fix i64842: because Undo has a very special way to handle header/footer content
+ // we have to copy the page descriptor before calling ChgPageDesc.
+ SwPageDesc aDesc( rChged );
+ {
+ ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
+ GetDoc()->CopyPageDesc(rChged, aDesc);
+ }
+ GetDoc()->ChgPageDescP( aDesc, pd );
+ EndAllActionAndCall();
+}
+
const SwPageDesc& SwFEShell::GetPageDesc( sal_uInt16 i ) const
{
return GetDoc()->GetPageDesc( i );
}
SwPageDesc* SwFEShell::FindPageDescByName( const OUString& rName,
- bool bGetFromPool,
- sal_uInt16* pPos )
+ bool bGetFromPool )
{
- SwPageDesc* pDesc = GetDoc()->FindPageDescByName( rName, pPos );
+ SwPageDesc* pDesc = GetDoc()->FindPageDescByName( rName );
if( !pDesc && bGetFromPool )
{
sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( rName, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC );
- if( USHRT_MAX != nPoolId &&
- 0 != (pDesc = GetDoc()->GetPageDescFromPool( nPoolId ))
- && pPos )
- // appended always
- *pPos = GetDoc()->GetPageDescCnt() - 1 ;
+ if( USHRT_MAX != nPoolId)
+ pDesc = GetDoc()->GetPageDescFromPool( nPoolId );
}
return pDesc;
}
@@ -148,11 +155,9 @@ sal_uInt16 SwFEShell::GetMousePageDesc( const Point &rPt ) const
while( pPage->GetNext() && rPt.Y() > pPage->Frm().Bottom() )
pPage = static_cast<const SwPageFrm*>( pPage->GetNext() );
SwDoc *pMyDoc = GetDoc();
- for ( sal_uInt16 i = 0; i < GetDoc()->GetPageDescCnt(); ++i )
- {
- if ( pPage->GetPageDesc() == &pMyDoc->GetPageDesc(i) )
- return i;
- }
+ sal_uInt16 pPos;
+ if (pMyDoc->FindPageDescByName( pPage->GetPageDesc()->GetName(), &pPos ) )
+ return pPos;
}
}
return 0;
@@ -166,12 +171,9 @@ sal_uInt16 SwFEShell::GetCurPageDesc( const bool bCalcFrm ) const
const SwPageFrm *pPage = pFrm->FindPageFrm();
if ( pPage )
{
- SwDoc *pMyDoc = GetDoc();
- for ( sal_uInt16 i = 0; i < GetDoc()->GetPageDescCnt(); ++i )
- {
- if ( pPage->GetPageDesc() == &pMyDoc->GetPageDesc(i) )
- return i;
- }
+ sal_uInt16 pPos;
+ if (GetDoc()->FindPageDescByName( pPage->GetPageDesc()->GetName(), &pPos ))
+ return pPos;
}
}
return 0;
diff --git a/sw/source/core/uibase/app/appenv.cxx b/sw/source/core/uibase/app/appenv.cxx
index afce13a..8d53a4c 100644
--- a/sw/source/core/uibase/app/appenv.cxx
+++ b/sw/source/core/uibase/app/appenv.cxx
@@ -401,13 +401,10 @@ void SwModule::InsertEnv( SfxRequest& rReq )
// Apply page description
- sal_uInt16 nPos;
- pSh->FindPageDescByName( pDesc->GetName(),
- false,
- &nPos );
-
- pSh->ChgPageDesc( nPos, *pDesc);
- pSh->ChgCurPageDesc(*pDesc);
+ SwPageDesc *pd = pSh->FindPageDescByName( pDesc->GetName(),
+ false );
+ pSh->ChgPageDescP( *pDesc, pd );
+ pSh->ChgCurPageDesc( *pDesc );
// Insert Frame
SwFlyFrmAttrMgr aMgr(false, pSh, FRMMGR_TYPE_ENVELP);
diff --git a/sw/source/filter/html/htmlcss1.cxx b/sw/source/filter/html/htmlcss1.cxx
index 50519b1..2f35e0a 100644
--- a/sw/source/filter/html/htmlcss1.cxx
+++ b/sw/source/filter/html/htmlcss1.cxx
@@ -87,16 +87,11 @@ static struct SwCSS1ItemIds
void SwCSS1Parser::ChgPageDesc( const SwPageDesc *pPageDesc,
const SwPageDesc& rNewPageDesc )
{
- sal_uInt16 nPageDescs = pDoc->GetPageDescCnt();
sal_uInt16 i;
- for( i=0; i<nPageDescs; i++ )
- if( pPageDesc == &pDoc->GetPageDesc(i) )
- {
- pDoc->ChgPageDesc( i, rNewPageDesc );
- return;
- }
-
- OSL_ENSURE( i<nPageDescs, "Seitenvorlage nicht gefunden" );
+ const SwPageDesc *spd = pDoc->FindPageDescByName( pPageDesc->GetName(), &i );
+ OSL_ENSURE( pPageDesc != spd, "Seitenvorlage nicht gefunden" );
+ if (pPageDesc == spd)
+ pDoc->ChgPageDesc( i, rNewPageDesc );
}
SwCSS1Parser::SwCSS1Parser( SwDoc *pD, sal_uInt32 aFHeights[7], const OUString& rBaseURL, bool bNewDoc ) :
@@ -1346,30 +1341,19 @@ SwPageDesc *SwCSS1Parser::GetMasterPageDesc()
return pDoc->GetPageDescFromPool( RES_POOLPAGE_HTML, false );
}
-static SwPageDesc *FindPageDesc( SwDoc *pDoc, sal_uInt16 nPoolId, sal_uInt16& rPage )
-{
- sal_uInt16 nPageDescs = pDoc->GetPageDescCnt();
- for( rPage=0; rPage < nPageDescs &&
- pDoc->GetPageDesc(rPage).GetPoolFmtId() != nPoolId; rPage++ )
- ;
-
- return rPage < nPageDescs ? &pDoc->GetPageDesc( rPage ) : 0;
-}
-
const SwPageDesc *SwCSS1Parser::GetPageDesc( sal_uInt16 nPoolId, bool bCreate )
{
if( RES_POOLPAGE_HTML == nPoolId )
return pDoc->GetPageDescFromPool( RES_POOLPAGE_HTML, false );
- sal_uInt16 nPage;
- const SwPageDesc *pPageDesc = FindPageDesc( pDoc, nPoolId, nPage );
+ const SwPageDesc *pPageDesc = pDoc->FindPageDescByPoolId( nPoolId );
if( !pPageDesc && bCreate )
{
// Die erste Seite wird aus der rechten Seite erzeugt, wenn es die
// gibt.
SwPageDesc *pMasterPageDesc = 0;
if( RES_POOLPAGE_FIRST == nPoolId )
- pMasterPageDesc = FindPageDesc( pDoc, RES_POOLPAGE_RIGHT, nPage );
+ pMasterPageDesc = pDoc->FindPageDescByPoolId( RES_POOLPAGE_RIGHT );
if( !pMasterPageDesc )
pMasterPageDesc = pDoc->GetPageDescFromPool( RES_POOLPAGE_HTML, false );
@@ -1378,7 +1362,7 @@ const SwPageDesc *SwCSS1Parser::GetPageDesc( sal_uInt16 nPoolId, bool bCreate )
GetPageDescFromPool( nPoolId, false );
// dazu brauchen wir auch die Nummer der neuen Vorlage
- pPageDesc = FindPageDesc( pDoc, nPoolId, nPage );
+ pPageDesc = pDoc->FindPageDescByPoolId( nPoolId );
OSL_ENSURE( pPageDesc==pNewPageDesc, "Seitenvorlage nicht gefunden" );
pDoc->CopyPageDesc( *pMasterPageDesc, *pNewPageDesc, false );
diff --git a/sw/source/filter/html/htmlsect.cxx b/sw/source/filter/html/htmlsect.cxx
index 8c10ed1..09bc39f 100644
--- a/sw/source/filter/html/htmlsect.cxx
+++ b/sw/source/filter/html/htmlsect.cxx
@@ -202,14 +202,7 @@ void SwHTMLParser::NewDivision( int nToken )
pDoc->DelFullPara( aDelPam );
// Die Seitenvorlage aktualisieren
- for( sal_uInt16 i=0; i < pDoc->GetPageDescCnt(); i++ )
- {
- if( RES_POOLPAGE_HTML == pDoc->GetPageDesc(i).GetPoolFmtId() )
- {
- pDoc->ChgPageDesc( i, *pPageDesc );
- break;
- }
- }
+ pDoc->ChgPageDescP( *pDoc->FindPageDescByPoolId( RES_POOLPAGE_HTML ) );
}
SwPosition aNewPos( SwNodeIndex( rCntntStIdx, 1 ), SwIndex( pCNd, 0 ) );
diff --git a/sw/source/filter/inc/fltshell.hxx b/sw/source/filter/inc/fltshell.hxx
index 71cc1db..0cc1744 100644
--- a/sw/source/filter/inc/fltshell.hxx
+++ b/sw/source/filter/inc/fltshell.hxx
@@ -537,7 +537,6 @@ class SwFltShell
SwPaM* pPaM;
OUString sBaseURL;
- sal_uInt16 nPageDescOffset; // fuers update der pagedescs
rtl_TextEncoding eSrcCharSet; // charset der quelle
friend class SwFltControlStack;
bool bNewDoc;
@@ -691,8 +690,6 @@ public:
const OUString& GetBaseURL() const { return sBaseURL; }
};
-SW_DLLPUBLIC void UpdatePageDescs(SwDoc &rDoc, sal_uInt16 nInPageDescOffset);
-
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww1/fltshell.cxx b/sw/source/filter/ww1/fltshell.cxx
index ff09448..3f3fd7d 100644
--- a/sw/source/filter/ww1/fltshell.cxx
+++ b/sw/source/filter/ww1/fltshell.cxx
@@ -1024,7 +1024,6 @@ SwFltShell::SwFltShell(SwDoc* pDoc, SwPaM& rPaM, const OUString& rBaseURL, bool
aEndStack(pDoc, nFieldFl),
pPaM(new SwPaM(*(rPaM.GetPoint()))),
sBaseURL(rBaseURL),
- nPageDescOffset(GetDoc().GetPageDescCnt()),
eSrcCharSet(RTL_TEXTENCODING_MS_1252),
bNewDoc(bNew),
bStdPD(false),
@@ -1062,8 +1061,6 @@ SwFltShell::SwFltShell(SwDoc* pDoc, SwPaM& rPaM, const OUString& rBaseURL, bool
SwFltShell::~SwFltShell()
{
- sal_uInt16 i;
-
if (eSubMode == Style)
EndStyle();
if( pOutDoc->IsInTable() ) // if not properly terminated
@@ -1077,9 +1074,10 @@ SwFltShell::~SwFltShell()
aStack.SetAttr(*pPaM->GetPoint(), 0, false);
aEndStack.SetAttr(*pPaM->GetPoint(), 0, false);
aEndStack.SetAttr(*pPaM->GetPoint(), 0, false);
+
+ SwDoc& rDoc = GetDoc();
if( bProtect ){ // The entire document is supposed to be protected
- SwDoc& rDoc = GetDoc();
// 1. Create SectionFmt and Section
SwSectionFmt* pSFmt = rDoc.MakeSectionFmt( 0 );
SwSectionData aSectionData(CONTENT_SECTION, OUString("PMW-Protect"));
@@ -1100,15 +1098,13 @@ SwFltShell::~SwFltShell()
pDocSh->SetReadOnlyUI( true );
}
}
- // Update document page descriptors (only this way also left
- // pages get adjusted)
- GetDoc().ChgPageDesc( 0, GetDoc().GetPageDesc( 0 )); // PageDesc "Standard"
- for (i=nPageDescOffset;i<GetDoc().GetPageDescCnt();i++)
- {
- const SwPageDesc& rPD = GetDoc().GetPageDesc(i);
- GetDoc().ChgPageDesc(i, rPD);
- }
+ sal_uInt16 i;
+
+ // Update document page descriptors (only this way also left
+ // pages get adjusted)
+ for (i = 0 ; i < rDoc.GetPageDescCnt(); i++)
+ GetDoc().ChgPageDescP( rDoc.GetPageDesc(i) );
delete pPaM;
for (i=0; i<sizeof(pColls)/sizeof(*pColls); i++)
@@ -2139,19 +2135,4 @@ void SwFltShell::NextStyle(sal_uInt16 nWhich, sal_uInt16 nNext)
*pColls[nNext]->GetColl() );
}
-// UpdatePageDescs needs to be called at end of parsing to make Writer actually
-// accept Pagedescs contents
-void UpdatePageDescs(SwDoc &rDoc, sal_uInt16 nInPageDescOffset)
-{
- // Update document page descriptors (only this way also left pages
- // get adjusted)
-
- // PageDesc "Standard"
- rDoc.ChgPageDesc(0, rDoc.GetPageDesc(0));
-
- // PageDescs "Convert..."
- for (sal_uInt16 i = nInPageDescOffset; i < rDoc.GetPageDescCnt(); ++i)
- rDoc.ChgPageDesc(i, rDoc.GetPageDesc(i));
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
index 8b8b21b..b7601bf 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -489,12 +489,10 @@ void RtfExport::WritePageDescTable()
OutPageDescription(rPageDesc, false, false);
// search for the next page description
- sal_uInt16 i = nSize;
- while (i)
- if (rPageDesc.GetFollow() == &pDoc->GetPageDesc(--i))
- break;
+ sal_uInt16 nPos;
+ pDoc->FindPageDescByName(rPageDesc.GetFollow()->GetName(), &nPos);
Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PGDSCNXT);
- OutULong(i).WriteChar(' ');
+ OutULong( nPos ).WriteChar(' ');
Strm().WriteCharPtr(msfilter::rtfutil::OutString(rPageDesc.GetName(), eDefaultEncoding).getStr()).WriteCharPtr(";}");
}
Strm().WriteChar('}').WriteCharPtr(SAL_NEWLINE_STRING);
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 8baad18..af08371 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -4895,8 +4895,6 @@ sal_uLong SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos)
pAnchorStck = new SwWW8FltAnchorStack(&rDoc, nFieldFlags);
- sal_uInt16 nPageDescOffset = rDoc.GetPageDescCnt();
-
SwNodeIndex aSttNdIdx( rDoc.GetNodes() );
SwRelNumRuleSpaces aRelNumRule(rDoc, mbNewDoc);
@@ -5314,7 +5312,10 @@ sal_uLong SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss, const SwPosition &rPos)
if (mbNewDoc)
rDoc.SetRedlineMode((RedlineMode_t)( eMode ));
- UpdatePageDescs(rDoc, nPageDescOffset);
+ // Update document page descriptors (only this way also left pages
+ // get adjusted)
+ for (sal_uInt16 i = 0; i < rDoc.GetPageDescCnt(); ++i)
+ rDoc.ChgPageDescP( rDoc.GetPageDesc(i) );
delete pPaM, pPaM = 0;
return nErrRet;
commit b37b2efdff865ae81daa410dfa7207606e7dca47
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date: Mon May 12 16:30:34 2014 +0200
Change MakePageDesc return type
Almost everybody except SwDoc::ClearDoc just use the index once
to get the SwPageDesc pointer.
As the index will be instable for delete and insert, this
just adds an additional lookup to ClearDoc and let everybody
else use the SwPageDesc pointer.
Change-Id: I4b2491813530fd3efb2480e389912c410c221168
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index fee9d63..a92951e8 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1308,9 +1308,9 @@ public:
void DelPageDesc( const OUString & rName, bool bBroadcast = false);
void DelPageDesc( sal_uInt16 i, bool bBroadcast = false );
void PreDelPageDesc(SwPageDesc * pDel);
- sal_uInt16 MakePageDesc( const OUString &rName, const SwPageDesc* pCpy = 0,
- bool bRegardLanguage = true,
- bool bBroadcast = false);
+ SwPageDesc* MakePageDesc( const OUString &rName, const SwPageDesc* pCpy = 0,
+ bool bRegardLanguage = true,
+ bool bBroadcast = false);
void BroadcastStyleOperation(const OUString& rName, SfxStyleFamily eFamily,
sal_uInt16 nOp);
diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx
index 984db36..a9f6962 100644
--- a/sw/source/core/attr/swatrset.cxx
+++ b/sw/source/core/attr/swatrset.cxx
@@ -394,8 +394,7 @@ void SwAttrSet::CopyToModify( SwModify& rMod ) const
pPgDesc->GetName() );
if( !pDstPgDesc )
{
- pDstPgDesc = &pDstDoc->GetPageDesc(
- pDstDoc->MakePageDesc( pPgDesc->GetName() ));
+ pDstPgDesc = pDstDoc->MakePageDesc( pPgDesc->GetName() );
pDstDoc->CopyPageDesc( *pPgDesc, *pDstPgDesc );
}
SwFmtPageDesc aDesc( pDstPgDesc );
diff --git a/sw/source/core/doc/docdesc.cxx b/sw/source/core/doc/docdesc.cxx
index 63d4787..c4d767a 100644
--- a/sw/source/core/doc/docdesc.cxx
+++ b/sw/source/core/doc/docdesc.cxx
@@ -587,8 +587,8 @@ void SwDoc::DelPageDesc( sal_uInt16 i, bool bBroadcast )
SetModified();
}
-sal_uInt16 SwDoc::MakePageDesc( const OUString &rName, const SwPageDesc *pCpy,
- bool bRegardLanguage, bool bBroadcast)
+SwPageDesc* SwDoc::MakePageDesc( const OUString &rName, const SwPageDesc *pCpy,
+ bool bRegardLanguage, bool bBroadcast)
{
SwPageDesc *pNew;
if( pCpy )
@@ -631,7 +631,7 @@ sal_uInt16 SwDoc::MakePageDesc( const OUString &rName, const SwPageDesc *pCpy,
}
SetModified();
- return (maPageDescs.size()-1);
+ return pNew;
}
// We collect the GlobalNames of the servers at runtime, who don't want to be notified
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 2b902e2..3826652 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -1971,7 +1971,7 @@ void SwDoc::CopyFmtArr( const SwFmtsBase& rSourceArr,
SwPageDescs::const_iterator it = maPageDescs.find( sPageDesc );
SwPageDesc *pPageDesc;
if( it == maPageDescs.end() )
- pPageDesc = maPageDescs[ MakePageDesc( sPageDesc->GetName() ) ];
+ pPageDesc = MakePageDesc( sPageDesc->GetName() );
else
pPageDesc = const_cast<SwPageDesc*>( *it );
aPageDesc.RegisterToPageDesc( *pPageDesc );
@@ -2102,7 +2102,7 @@ void SwDoc::CopyPageDesc( const SwPageDesc& rSrcDesc, SwPageDesc& rDstDesc,
if( it == maPageDescs.end() )
{
// copy
- pFollow = maPageDescs[ MakePageDesc( rSrcDesc.GetFollow()->GetName() ) ];
+ pFollow = MakePageDesc( sFollow->GetName() );
CopyPageDesc( *rSrcDesc.GetFollow(), *pFollow );
}
else
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index a1945ef..5bbb838 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -719,8 +719,7 @@ void SwDoc::ClearDoc()
InitTOXTypes();
// create a dummy pagedesc for the layout
- sal_uInt16 nDummyPgDsc = MakePageDesc(OUString("?DUMMY?"));
- SwPageDesc* pDummyPgDsc = maPageDescs[ nDummyPgDsc ];
+ SwPageDesc* pDummyPgDsc = MakePageDesc(OUString("?DUMMY?"));
SwNodeIndex aSttIdx( *GetNodes().GetEndOfContent().StartOfSectionNode(), 1 );
// create the first one over and over again (without attributes/style etc.
@@ -769,7 +768,7 @@ void SwDoc::ClearDoc()
mpOutlineRule->SetCountPhantoms( !get(IDocumentSettingAccess::OLD_NUMBERING) );
// remove the dummy pagedec from the array and delete all the old ones
- maPageDescs.erase( maPageDescs.begin() + nDummyPgDsc );
+ maPageDescs.erase( pDummyPgDsc );
maPageDescs.DeleteAndDestroyAll();
// Delete for Collections
@@ -807,12 +806,12 @@ void SwDoc::ClearDoc()
GetPageDescFromPool( RES_POOLPAGE_STANDARD );
pFirstNd->ChgFmtColl( GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
- nDummyPgDsc = maPageDescs.size();
- maPageDescs.insert( pDummyPgDsc );
+ std::pair<SwPageDescs::const_iterator, bool> res = maPageDescs.insert( pDummyPgDsc );
+ SAL_WARN_IF(res.second == false, "sw", "ClearDoc: inserted already existing PageDesc" );
// set the layout back to the new standard pagedesc
pFirstNd->ResetAllAttr();
// delete now the dummy pagedesc
- DelPageDesc( nDummyPgDsc );
+ DelPageDesc( std::distance( maPageDescs.begin(), res.first) );
}
void SwDoc::SetPreviewPrtData( const SwPagePreviewPrtData* pNew )
diff --git a/sw/source/core/doc/poolfmt.cxx b/sw/source/core/doc/poolfmt.cxx
index 0ef2057..6547569 100644
--- a/sw/source/core/doc/poolfmt.cxx
+++ b/sw/source/core/doc/poolfmt.cxx
@@ -1479,13 +1479,11 @@ SwPageDesc* SwDoc::GetPageDescFromPool( sal_uInt16 nId, bool bRegardLanguage )
const OUString aNm( aResId );
const bool bIsModified = IsModified();
- sal_uInt16 nPageDescIdx = 0;
{
::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo());
- nPageDescIdx = MakePageDesc( aNm, 0, bRegardLanguage );
+ pNewPgDsc = MakePageDesc( aNm, 0, bRegardLanguage );
}
- pNewPgDsc = maPageDescs[ nPageDescIdx ];
pNewPgDsc->SetPoolFmtId( nId );
if ( !bIsModified )
{
diff --git a/sw/source/core/uibase/app/docstyle.cxx b/sw/source/core/uibase/app/docstyle.cxx
index 848649c..ec561b0 100644
--- a/sw/source/core/uibase/app/docstyle.cxx
+++ b/sw/source/core/uibase/app/docstyle.cxx
@@ -1852,8 +1852,7 @@ void SwDocStyleSheet::Create()
pDesc = lcl_FindPageDesc( rDoc, aName );
if( !pDesc )
{
- sal_uInt16 nId = rDoc.MakePageDesc(aName);
- pDesc = &rDoc.GetPageDesc(nId);
+ pDesc = rDoc.MakePageDesc(aName);
}
break;
diff --git a/sw/source/core/uibase/dbui/dbmgr.cxx b/sw/source/core/uibase/dbui/dbmgr.cxx
index 4574a91..d574148 100644
--- a/sw/source/core/uibase/dbui/dbmgr.cxx
+++ b/sw/source/core/uibase/dbui/dbmgr.cxx
@@ -792,12 +792,10 @@ static void lcl_CopyFollowPageDesc(
{
SwDoc* pTargetDoc = rTargetShell.GetDoc();
OUString sNewFollowPageDesc = lcl_FindUniqueName(&rTargetShell, sFollowPageDesc, nDocNo );
- sal_uInt16 nNewDesc = pTargetDoc->MakePageDesc( sNewFollowPageDesc );
- SwPageDesc& rTargetFollowPageDesc = pTargetDoc->GetPageDesc( nNewDesc );
-
- pTargetDoc->CopyPageDesc( *pFollowPageDesc, rTargetFollowPageDesc, false );
+ SwPageDesc* rTargetFollowPageDesc = pTargetDoc->MakePageDesc( sNewFollowPageDesc );
+ pTargetDoc->CopyPageDesc( *pFollowPageDesc, *rTargetFollowPageDesc, false );
SwPageDesc aDesc( rTargetPageDesc );
- aDesc.SetFollow( &rTargetFollowPageDesc );
+ aDesc.SetFollow( rTargetFollowPageDesc );
pTargetDoc->ChgPageDesc( rTargetPageDesc.GetName(), aDesc );
}
}
diff --git a/sw/source/filter/ww1/fltshell.cxx b/sw/source/filter/ww1/fltshell.cxx
index 5eca85e..ff09448 100644
--- a/sw/source/filter/ww1/fltshell.cxx
+++ b/sw/source/filter/ww1/fltshell.cxx
@@ -2087,17 +2087,14 @@ SwPageDesc* SwFltShell::MakePageDesc(SwPageDesc* pFirstPageDesc)
bool bFollow = (pFirstPageDesc != 0);
SwPageDesc* pNewPD;
- sal_uInt16 nPos;
if (bFollow && pFirstPageDesc->GetFollow() != pFirstPageDesc)
return pFirstPageDesc; // Error: already has Follow
// Detection of duplicate names still missing (low probability of this
// actually occurring)
- nPos = GetDoc().MakePageDesc( SwViewShell::GetShellRes()->GetPageDescName(
+ pNewPD = GetDoc().MakePageDesc( SwViewShell::GetShellRes()->GetPageDescName(
GetDoc().GetPageDescCnt(), bFollow ? ShellResource::FOLLOW_PAGE : ShellResource::NORMAL_PAGE),
pFirstPageDesc, false );
-
- pNewPD = &GetDoc().GetPageDesc(nPos);
if (bFollow)
{
// This one follows pPageDesc
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 41bfc4f..8baad18 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -4353,10 +4353,9 @@ SwFmtPageDesc wwSectionManager::SetSwFmtPageDesc(mySegIter &rIter,
}
else
{
- sal_uInt16 nPos = mrReader.rDoc.MakePageDesc(
+ rIter->mpPage = mrReader.rDoc.MakePageDesc(
SwViewShell::GetShellRes()->GetPageDescName(mnDesc, ShellResource::NORMAL_PAGE),
0, false);
- rIter->mpPage = &mrReader.rDoc.GetPageDesc(nPos);
}
OSL_ENSURE(rIter->mpPage, "no page!");
if (!rIter->mpPage)
commit 838d9a6152fd95564dca7fa2055d9934f793a5d4
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date: Wed May 14 15:03:53 2014 +0200
Optimize SwPageDesc lookup by pool ID
There are just ten default page pool style IDs.
So instead of walking the whole style list to find the matching
style ID, this introduces an additional index / array for faster
lookup.
Change-Id: Iacfa40c76e5502dc90665be0a96388de50d5ec16
diff --git a/sw/inc/pagedesc.hxx b/sw/inc/pagedesc.hxx
index 28aeb90..02a68e9 100644
--- a/sw/inc/pagedesc.hxx
+++ b/sw/inc/pagedesc.hxx
@@ -26,6 +26,7 @@
#include <frmfmt.hxx>
#include <editeng/numitem.hxx>
#include <editeng/borderline.hxx>
+#include "poolfmt.hxx"
class SfxPoolItem;
class SwTxtFmtColl;
@@ -234,7 +235,7 @@ public:
/// Query and set PoolFormat-Id.
sal_uInt16 GetPoolFmtId() const { return aMaster.GetPoolFmtId(); }
- void SetPoolFmtId( sal_uInt16 nId ) { aMaster.SetPoolFmtId( nId ); }
+ void SetPoolFmtId( sal_uInt16 nId );
sal_uInt16 GetPoolHelpId() const { return aMaster.GetPoolHelpId(); }
void SetPoolHelpId( sal_uInt16 nId ) { aMaster.SetPoolHelpId( nId ); }
sal_uInt8 GetPoolHlpFileId() const { return aMaster.GetPoolHlpFileId(); }
@@ -348,15 +349,30 @@ public:
typedef std::vector<SwPageDesc*> SwPageDescsBase;
-// PageDescriptor-interface, Array because of inlines.
+#define RES_POOLPAGE_SIZE (RES_POOLPAGE_END - RES_POOLPAGE_BEGIN)
+
// Mimics o3tl::sorted_vector interface
class SwPageDescs : private SwPageDescsBase
{
+ // to update the poolpages array on PoolFmtId change
+ friend void SwPageDesc::SetPoolFmtId( sal_uInt16 nId );
+
public:
typedef typename SwPageDescsBase::const_iterator const_iterator;
typedef typename SwPageDescsBase::size_type size_type;
typedef typename SwPageDescsBase::value_type value_type;
+private:
+ // fast index for pool page resources
+ value_type poolpages[RES_POOLPAGE_SIZE];
+
+ void _erase( const value_type& x );
+ bool IsIdInPoolRange( sal_uInt16 nId, bool allowDefault ) const;
+
+ bool SetPoolPageDesc( const value_type& x, sal_uInt16 nId = USHRT_MAX );
+
+public:
+ SwPageDescs();
// the destructor will free all objects still in the vector
~SwPageDescs();
@@ -383,6 +399,7 @@ public:
const_iterator end() const { return SwPageDescsBase::end(); }
bool Contains( const value_type& x ) const;
+ value_type GetPoolPageDesc( sal_uInt16 nId ) const;
private:
typedef typename SwPageDescsBase::iterator iterator;
diff --git a/sw/source/core/layout/pagedesc.cxx b/sw/source/core/layout/pagedesc.cxx
index 2490467..8d67fef 100644
--- a/sw/source/core/layout/pagedesc.cxx
+++ b/sw/source/core/layout/pagedesc.cxx
@@ -245,6 +245,19 @@ void SwPageDesc::RegisterChange()
}
}
+void SwPageDesc::SetPoolFmtId( sal_uInt16 nId )
+{
+ sal_uInt16 nIdOld = aMaster.GetPoolFmtId();
+ if ( nId == nIdOld )
+ return;
+ aMaster.SetPoolFmtId( nId );
+ if (list != 0) {
+ bool ok = list->SetPoolPageDesc( this, nIdOld );
+ SAL_WARN_IF(!ok, "sw",
+ "Unable to set register the PoolFmtId from SetPoolFmtId");
+ }
+}
+
/// special handling if the style of the grid alignment changes
void SwPageDesc::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
{
@@ -480,6 +493,11 @@ SwPageDescExt::operator SwPageDesc() const
return aResult;
}
+SwPageDescs::SwPageDescs()
+{
+ memset(poolpages, 0, sizeof(value_type) * RES_POOLPAGE_SIZE);
+}
+
SwPageDescs::~SwPageDescs()
{
DeleteAndDestroyAll();
@@ -489,27 +507,49 @@ void SwPageDescs::DeleteAndDestroyAll()
{
for( const_iterator it = begin(); it != end(); ++it )
delete *it;
+ memset(poolpages, 0, sizeof(value_type) * RES_POOLPAGE_SIZE);
clear();
}
std::pair<SwPageDescs::const_iterator,bool> SwPageDescs::insert( const value_type& x )
{
+ sal_uInt16 nId = x->GetPoolFmtId();
+ SAL_WARN_IF(nId != USHRT_MAX && NULL != GetPoolPageDesc( nId ),
+ "sw", "Inserting already assigned pool ID item!");
+
const_iterator const ret = find( x );
if (ret == end()) {
SwPageDescsBase::push_back( x );
- SAL_WARN_IF(x->list == 0, "sw", "Inserting already assigned item");
+ if (x->list != 0) {
+ SAL_WARN("sw", "Inserting already assigned item!");
+ SAL_WARN_IF(x->list != this, "sw",
+ "Inserting assigned item from other list!");
+ }
x->list = this;
+ if (nId != USHRT_MAX)
+ poolpages[ nId - RES_POOLPAGE_BEGIN ] = x;
return std::make_pair(end() - 1 , true);
}
return std::make_pair(ret, false);
}
+void SwPageDescs::_erase( const value_type& x )
+{
+ sal_uInt16 nId = x->GetPoolFmtId();
+ if (nId != USHRT_MAX) {
+ SAL_WARN_IF(poolpages[ nId - RES_POOLPAGE_BEGIN ] != x,
+ "sw", "SwPageDesc with PoolId not correctly registered!");
+ poolpages[ nId - RES_POOLPAGE_BEGIN ] = NULL;
+ }
+ x->list = 0;
+}
+
SwPageDescs::size_type SwPageDescs::erase( const value_type& x )
{
const_iterator const ret = find( x );
if (ret != end()) {
SwPageDescsBase::erase( begin_nonconst() + (ret - begin()) );
- x->list = 0;
+ _erase( x );
return 1;
}
return 0;
@@ -522,7 +562,7 @@ void SwPageDescs::erase( size_type index )
void SwPageDescs::erase( const_iterator const& position )
{
- (*position)->list = 0;
+ _erase( *position );
SwPageDescsBase::erase( begin_nonconst() + (position - begin()) );
}
@@ -561,4 +601,38 @@ bool SwPageDescs::Contains( const SwPageDescs::value_type& x ) const
return (x->list == this);
}
+bool SwPageDescs::IsIdInPoolRange( sal_uInt16 nId, bool allowDefault ) const
+{
+ bool res = (nId >= RES_POOLPAGE_BEGIN && nId < RES_POOLPAGE_END);
+ if (!res && allowDefault)
+ res = (nId == USHRT_MAX);
+ SAL_WARN_IF(!res, "sw", "PageDesc pool id out of range");
+ return res;
+}
+
+bool SwPageDescs::SetPoolPageDesc( const value_type& x, sal_uInt16 nIdOld )
+{
+ sal_uInt16 nId = x->GetPoolFmtId();
+ if (!IsIdInPoolRange(nIdOld, true)) return false;
+ if (!IsIdInPoolRange(nId, true)) return false;
+
+ if (nIdOld != USHRT_MAX) {
+ SAL_WARN_IF(x != poolpages[ nIdOld - RES_POOLPAGE_BEGIN ],
+ "sw", "Old PageDesc pool id pointer != object");
+ poolpages[ nIdOld - RES_POOLPAGE_BEGIN ] = NULL;
+ }
+ if (nId != USHRT_MAX) {
+ SAL_WARN_IF(NULL != poolpages[ nId - RES_POOLPAGE_BEGIN ],
+ "sw", "SwPageDesc pool ID already assigned!");
+ poolpages[ nId - RES_POOLPAGE_BEGIN ] = x;
+ }
+ return true;
+}
+
+SwPageDescs::value_type SwPageDescs::GetPoolPageDesc( sal_uInt16 nId ) const
+{
+ if (!IsIdInPoolRange(nId, false)) return NULL;
+ return poolpages[ nId - RES_POOLPAGE_BEGIN ];
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit cd1fc4d804b071bd1386a4821723c44e06aef10a
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date: Mon May 12 16:00:02 2014 +0200
Change SwPageDescs to o3tl::sorted_vector like API
This moves the SwPageDescs class to pagedesc.hxx, changes the
std::vector inheritance to private and extends the class to a
o3tl::sorted_vector compatible API.
The insert internally uses still uses push_back.
This also drops multiple implementations for the "find SwPageDesc
by name algorithm".
This should just be a cleanup patch and is a preparation for the
change of SwPageDescs from vector to o3tl::sorted_vector.
Change-Id: I08561c139d1af9bad6ca68be27466fac33fab384
diff --git a/helpcontent2 b/helpcontent2
index 2ef15cb..fdfcaa9 160000
--- a/helpcontent2
+++ b/helpcontent2
@@ -1 +1 @@
-Subproject commit 2ef15cb93840390d9927f64bddb958ad699cb792
+Subproject commit fdfcaa991224f6ac15fdc778e0a301b9285208eb
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 4e833d8..fee9d63 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -68,6 +68,7 @@ class SwList;
#include <com/sun/star/chart2/data/XDataProvider.hpp>
#include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
#include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
+#include <pagedesc.hxx>
#include <boost/unordered_map.hpp>
@@ -140,7 +141,6 @@ class SwNodeRange;
class SwNodes;
class SwNumRule;
class SwNumRuleTbl;
-class SwPageDesc;
class SwPagePreviewPrtData;
class SwRangeRedline;
class SwRedlineTbl;
@@ -231,14 +231,6 @@ namespace sfx2 {
class LinkManager;
}
-// PageDescriptor-interface, Array because of inlines.
-class SwPageDescs : public std::vector<SwPageDesc*>
-{
-public:
- // the destructor will free all objects still in the vector
- ~SwPageDescs();
-};
-
// forward declaration
void SetAllScriptItem( SfxItemSet& rSet, const SfxPoolItem& rItem );
@@ -1292,6 +1284,8 @@ public:
SwPageDesc& GetPageDesc( sal_uInt16 i ) { return *maPageDescs[i]; }
SwPageDesc* FindPageDescByName( const OUString& rName,
sal_uInt16* pPos = 0 ) const;
+ SwPageDesc* FindPageDescByName( const OUString& rName,
+ sal_uInt16* pPos = 0 );
/** Copy the complete PageDesc - beyond document and "deep"!
Optionally copying of PoolFmtId, -HlpId can be prevented. */
@@ -1309,10 +1303,8 @@ public:
{ CopyPageDescHeaderFooterImpl( false, rSrcFmt, rDestFmt ); }
// For Reader
- SwPageDesc * GetPageDesc( const OUString & rName );
void ChgPageDesc( const OUString & rName, const SwPageDesc& );
void ChgPageDesc( sal_uInt16 i, const SwPageDesc& );
- bool FindPageDesc( const OUString & rName, sal_uInt16 * pFound );
void DelPageDesc( const OUString & rName, bool bBroadcast = false);
void DelPageDesc( sal_uInt16 i, bool bBroadcast = false );
void PreDelPageDesc(SwPageDesc * pDel);
diff --git a/sw/inc/pagedesc.hxx b/sw/inc/pagedesc.hxx
index a15a851..28aeb90 100644
--- a/sw/inc/pagedesc.hxx
+++ b/sw/inc/pagedesc.hxx
@@ -30,6 +30,7 @@
class SfxPoolItem;
class SwTxtFmtColl;
class SwNode;
+class SwPageDescs;
/// Separator line adjustment.
enum SwFtnAdj
@@ -130,6 +131,9 @@ namespace nsUseOnPage
class SW_DLLPUBLIC SwPageDesc : public SwModify
{
friend class SwDoc;
+ // How to define the friend functions _erase and insert
+ // to update the list member
+ friend class SwPageDescs;
OUString aDescName;
SvxNumberType aNumType;
@@ -149,20 +153,24 @@ class SW_DLLPUBLIC SwPageDesc : public SwModify
/// Footnote information.
SwPageFtnInfo aFtnInfo;
+ // The assigned list.
+ SwPageDescs *list;
+
/** Called for mirroring of Chg (doc).
No adjustment at any other place. */
SAL_DLLPRIVATE void Mirror();
SAL_DLLPRIVATE void ResetAllAttr( bool bLeft );
- SAL_DLLPRIVATE SwPageDesc(const OUString&, SwFrmFmt*, SwDoc *pDc );
+ SAL_DLLPRIVATE SwPageDesc( const OUString&, SwFrmFmt*, SwDoc *pDc );
protected:
virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNewValue ) SAL_OVERRIDE;
public:
OUString GetName() const { return aDescName; }
- void SetName( const OUString& rNewName ) { aDescName = rNewName; }
+ // only called in sw/source/core/uibase/app/docstyle.cxx
+ void SetName( const OUString& rNewName );
bool GetLandscape() const { return bLandscape; }
void SetLandscape( bool bNew ) { bLandscape = bNew; }
@@ -338,6 +346,50 @@ public:
operator SwPageDesc() const; // #i7983#
};
+typedef std::vector<SwPageDesc*> SwPageDescsBase;
+
+// PageDescriptor-interface, Array because of inlines.
+// Mimics o3tl::sorted_vector interface
+class SwPageDescs : private SwPageDescsBase
+{
+public:
+ typedef typename SwPageDescsBase::const_iterator const_iterator;
+ typedef typename SwPageDescsBase::size_type size_type;
+ typedef typename SwPageDescsBase::value_type value_type;
+
+ // the destructor will free all objects still in the vector
+ ~SwPageDescs();
+
+ void DeleteAndDestroyAll();
+
+ using SwPageDescsBase::clear;
+ using SwPageDescsBase::empty;
+ using SwPageDescsBase::size;
+
+ std::pair<const_iterator,bool> insert( const value_type& x );
+ size_type erase( const value_type& x );
+ void erase( size_type index );
+ void erase( const_iterator const& position );
+
+ const value_type& front() const { return SwPageDescsBase::front(); }
+ const value_type& back() const { return SwPageDescsBase::back(); }
+ const value_type& operator[]( size_t index ) const
+ { return SwPageDescsBase::operator[]( index ); }
+
+ const_iterator find( const OUString &name ) const;
+ const_iterator find( const value_type& x ) const;
+
+ const_iterator begin() const { return SwPageDescsBase::begin(); }
+ const_iterator end() const { return SwPageDescsBase::end(); }
+
+ bool Contains( const value_type& x ) const;
+
+private:
+ typedef typename SwPageDescsBase::iterator iterator;
+ iterator begin_nonconst() { return SwPageDescsBase::begin(); }
+ iterator end_nonconst() { return SwPageDescsBase::end(); }
+};
+
#endif // INCLUDED_SW_INC_PAGEDESC_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/docdesc.cxx b/sw/source/core/doc/docdesc.cxx
index 062fba3..63d4787 100644
--- a/sw/source/core/doc/docdesc.cxx
+++ b/sw/source/core/doc/docdesc.cxx
@@ -617,7 +617,9 @@ sal_uInt16 SwDoc::MakePageDesc( const OUString &rName, const SwPageDesc *pCpy,
pNew->GetFirstMaster().SetFmtAttr( SvxFrameDirectionItem(aFrameDirection, RES_FRAMEDIR) );
pNew->GetFirstLeft().SetFmtAttr( SvxFrameDirectionItem(aFrameDirection, RES_FRAMEDIR) );
}
- maPageDescs.push_back( pNew );
+
+ std::pair<SwPageDescs::const_iterator, bool> res = maPageDescs.insert( pNew );
+ SAL_WARN_IF(res.second == false, "sw", "MakePageDesc called with existing name" );
if (bBroadcast)
BroadcastStyleOperation(rName, SFX_STYLE_FAMILY_PAGE,
@@ -632,22 +634,6 @@ sal_uInt16 SwDoc::MakePageDesc( const OUString &rName, const SwPageDesc *pCpy,
return (maPageDescs.size()-1);
}
-SwPageDesc* SwDoc::FindPageDescByName( const OUString& rName, sal_uInt16* pPos ) const
-{
- SwPageDesc* pRet = 0;
- if( pPos ) *pPos = USHRT_MAX;
-
- for( sal_uInt16 n = 0, nEnd = maPageDescs.size(); n < nEnd; ++n )
- if( maPageDescs[ n ]->GetName() == rName )
- {
- pRet = maPageDescs[ n ];
- if( pPos )
- *pPos = n;
- break;
- }
- return pRet;
-}
-
// We collect the GlobalNames of the servers at runtime, who don't want to be notified
// about printer changes. Thereby saving loading a lot of objects (luckily all foreign
// objects are mapped to one ID).
@@ -774,40 +760,35 @@ IMPL_LINK( SwDoc, DoUpdateModifiedOLE, Timer *, )
return 0;
}
-bool SwDoc::FindPageDesc( const OUString & rName, sal_uInt16 * pFound)
+static SwPageDesc* lcl_FindPageDescByName( SwPageDescs *maPageDescs, const OUString & rName, sal_uInt16* pPos )
{
- bool bResult = false;
- sal_uInt16 nI;
- for (nI = 0; nI < maPageDescs.size(); nI++)
- {
- if (maPageDescs[nI]->GetName() == rName)
- {
- *pFound = nI;
- bResult = true;
- break;
- }
- }
-
- return bResult;
+ SwPageDescs::const_iterator it = maPageDescs->find( rName );
+ SwPageDesc* res = NULL;
+ if (it != maPageDescs->end() ) {
+ res = const_cast <SwPageDesc *>( *it );
+ if( pPos )
+ *pPos = std::distance( maPageDescs->begin(), it );
+ }
+ else if( pPos )
+ *pPos = USHRT_MAX;
+ return res;
}
-SwPageDesc * SwDoc::GetPageDesc( const OUString & rName )
+SwPageDesc* SwDoc::FindPageDescByName( const OUString & rName, sal_uInt16* pPos )
{
- SwPageDesc * aResult = NULL;
-
- sal_uInt16 nI;
-
- if (FindPageDesc(rName, &nI))
- aResult = maPageDescs[nI];
+ return lcl_FindPageDescByName( &maPageDescs, rName, pPos );
+}
- return aResult;
+SwPageDesc* SwDoc::FindPageDescByName( const OUString & rName, sal_uInt16* pPos ) const
+{
+ return lcl_FindPageDescByName( const_cast <SwPageDescs *>( &maPageDescs ), rName, pPos );
}
void SwDoc::DelPageDesc( const OUString & rName, bool bBroadcast )
{
sal_uInt16 nI;
- if (FindPageDesc(rName, &nI))
+ if (FindPageDescByName(rName, &nI))
DelPageDesc(nI, bBroadcast);
}
@@ -815,7 +796,7 @@ void SwDoc::ChgPageDesc( const OUString & rName, const SwPageDesc & rDesc)
{
sal_uInt16 nI;
- if (FindPageDesc(rName, &nI))
+ if (FindPageDescByName(rName, &nI))
ChgPageDesc(nI, rDesc);
}
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 8f1f976..2b902e2 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -1923,17 +1923,6 @@ SwGrfFmtColl* SwDoc::CopyGrfColl( const SwGrfFmtColl& rColl )
return pNewColl;
}
-static SwPageDesc* lcl_FindPageDesc( const SwPageDescs& rArr, const OUString& rName )
-{
- for( sal_uInt16 n = rArr.size(); n; )
- {
- SwPageDesc* pDesc = rArr[ --n ];
- if( pDesc->GetName() == rName )
- return pDesc;
- }
- return 0;
-}
-
void SwDoc::CopyFmtArr( const SwFmtsBase& rSourceArr,
SwFmtsBase& rDestArr,
FNCopyFmt fnCopyFmt,
@@ -1978,12 +1967,13 @@ void SwDoc::CopyFmtArr( const SwFmtsBase& rSourceArr,
((SwFmtPageDesc*)pItem)->GetPageDesc() )
{
SwFmtPageDesc aPageDesc( *(SwFmtPageDesc*)pItem );
- const OUString& rNm = aPageDesc.GetPageDesc()->GetName();
- SwPageDesc* pPageDesc = ::lcl_FindPageDesc( maPageDescs, rNm );
- if( !pPageDesc )
- {
- pPageDesc = maPageDescs[ MakePageDesc( rNm ) ];
- }
+ SwPageDesc *sPageDesc = aPageDesc.GetPageDesc();;
+ SwPageDescs::const_iterator it = maPageDescs.find( sPageDesc );
+ SwPageDesc *pPageDesc;
+ if( it == maPageDescs.end() )
+ pPageDesc = maPageDescs[ MakePageDesc( sPageDesc->GetName() ) ];
+ else
+ pPageDesc = const_cast<SwPageDesc*>( *it );
aPageDesc.RegisterToPageDesc( *pPageDesc );
SwAttrSet aTmpAttrSet( pSrc->GetAttrSet() );
aTmpAttrSet.Put( aPageDesc );
@@ -2106,15 +2096,17 @@ void SwDoc::CopyPageDesc( const SwPageDesc& rSrcDesc, SwPageDesc& rDstDesc,
if( rSrcDesc.GetFollow() != &rSrcDesc )
{
- SwPageDesc* pFollow = ::lcl_FindPageDesc( maPageDescs,
- rSrcDesc.GetFollow()->GetName() );
- if( !pFollow )
+ const SwPageDesc* sFollow = rSrcDesc.GetFollow();
+ SwPageDescs::const_iterator it = maPageDescs.find( const_cast<SwPageDesc*>( sFollow ) );
+ SwPageDesc* pFollow;
+ if( it == maPageDescs.end() )
{
// copy
- sal_uInt16 nPos = MakePageDesc( rSrcDesc.GetFollow()->GetName() );
- pFollow = maPageDescs[ nPos ];
+ pFollow = maPageDescs[ MakePageDesc( rSrcDesc.GetFollow()->GetName() ) ];
CopyPageDesc( *rSrcDesc.GetFollow(), *pFollow );
}
+ else
+ pFollow = *it;
rDstDesc.SetFollow( pFollow );
bNotifyLayout = true;
}
@@ -2223,7 +2215,7 @@ void SwDoc::ReplaceStyles( const SwDoc& rSource, bool bIncludePageStyles )
while( nCnt )
{
SwPageDesc *pSrc = rSource.maPageDescs[ --nCnt ];
- if( 0 == ::lcl_FindPageDesc( maPageDescs, pSrc->GetName() ) )
+ if( maPageDescs.end() == maPageDescs.find( pSrc ) )
MakePageDesc( pSrc->GetName() );
}
@@ -2231,7 +2223,7 @@ void SwDoc::ReplaceStyles( const SwDoc& rSource, bool bIncludePageStyles )
for( nCnt = rSource.maPageDescs.size(); nCnt; )
{
SwPageDesc *pSrc = rSource.maPageDescs[ --nCnt ];
- CopyPageDesc( *pSrc, *::lcl_FindPageDesc( maPageDescs, pSrc->GetName() ));
+ CopyPageDesc( *pSrc, **(maPageDescs.find( pSrc->GetName()) ));
}
}
}
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index d42dd9f..a1945ef 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -541,9 +541,7 @@ SwDoc::~SwDoc()
// Destroy these only after destroying the FmtIndices, because the content
// of headers/footers has to be deleted as well. If in the headers/footers
// there are still Flys registered at that point, we have a problem.
- BOOST_FOREACH(SwPageDesc *pPageDesc, maPageDescs)
- delete pPageDesc;
- maPageDescs.clear();
+ maPageDescs.DeleteAndDestroyAll();
// Delete content selections.
// Don't wait for the SwNodes dtor to destroy them; so that Formats
@@ -772,9 +770,7 @@ void SwDoc::ClearDoc()
// remove the dummy pagedec from the array and delete all the old ones
maPageDescs.erase( maPageDescs.begin() + nDummyPgDsc );
- BOOST_FOREACH(SwPageDesc *pPageDesc, maPageDescs)
- delete pPageDesc;
- maPageDescs.clear();
+ maPageDescs.DeleteAndDestroyAll();
// Delete for Collections
// So that we get rid of the dependencies
@@ -812,7 +808,7 @@ void SwDoc::ClearDoc()
GetPageDescFromPool( RES_POOLPAGE_STANDARD );
pFirstNd->ChgFmtColl( GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
nDummyPgDsc = maPageDescs.size();
- maPageDescs.push_back( pDummyPgDsc );
+ maPageDescs.insert( pDummyPgDsc );
// set the layout back to the new standard pagedesc
pFirstNd->ResetAllAttr();
// delete now the dummy pagedesc
diff --git a/sw/source/core/doc/poolfmt.cxx b/sw/source/core/doc/poolfmt.cxx
index 5340ee3..0ef2057 100644
--- a/sw/source/core/doc/poolfmt.cxx
+++ b/sw/source/core/doc/poolfmt.cxx
@@ -2197,7 +2197,7 @@ bool SwDoc::IsPoolPageDescUsed( sal_uInt16 nId ) const
{
OSL_ENSURE( RES_POOLPAGE_BEGIN <= nId && nId < RES_POOLPAGE_END,
"Wrong AutoFormat Id" );
- SwPageDesc *pNewPgDsc = 0;
+ const SwPageDesc *pNewPgDsc = 0;
bool bFnd = false;
for( sal_uInt16 n = 0; !bFnd && n < maPageDescs.size(); ++n )
{
diff --git a/sw/source/core/layout/pagedesc.cxx b/sw/source/core/layout/pagedesc.cxx
index e7641f2..2490467 100644
--- a/sw/source/core/layout/pagedesc.cxx
+++ b/sw/source/core/layout/pagedesc.cxx
@@ -50,7 +50,8 @@ SwPageDesc::SwPageDesc( const OUString& rName, SwFrmFmt *pFmt, SwDoc *pDc ) :
eUse( (UseOnPage)(nsUseOnPage::PD_ALL | nsUseOnPage::PD_HEADERSHARE | nsUseOnPage::PD_FOOTERSHARE | nsUseOnPage::PD_FIRSTSHARE ) ),
bLandscape( false ),
bHidden( false ),
- aFtnInfo()
+ aFtnInfo(),
+ list ( 0 )
{
}
@@ -69,7 +70,8 @@ SwPageDesc::SwPageDesc( const SwPageDesc &rCpy ) :
eUse( rCpy.ReadUseOn() ),
bLandscape( rCpy.GetLandscape() ),
bHidden( rCpy.IsHidden() ),
- aFtnInfo( rCpy.GetFtnInfo() )
+ aFtnInfo( rCpy.GetFtnInfo() ),
+ list ( 0 )
{
}
@@ -98,6 +100,32 @@ SwPageDesc::~SwPageDesc()
{
}
+void SwPageDesc::SetName( const OUString& rNewName )
+{
+ SwPageDescs *_list = list;
+ SwPageDescs::const_iterator it;
+ bool move_entry = false;
+
+ if (list) {
+ if( list->end() != list->find( rNewName ))
+ return;
+ // Optimize by implemeting move in o3tl::sorted_vector
+ it = list->find( this );
+ SAL_WARN_IF( list->end() == it, "sw", "SwPageDesc not found in expected list" );
+ move_entry = (it != list->begin());
+ if (move_entry)
+ // Clears list
+ list->erase( it );
+ }
+
+ aDescName = rNewName;
+
+ if (_list && move_entry)
+ // Sets list
+ _list->insert( this );
+}
+
+
/// Only the margin is mirrored.
/// Attributes like borders and so on are copied 1:1.
void SwPageDesc::Mirror()
@@ -331,16 +359,9 @@ void SwPageDesc::ChgFirstShare( bool bNew )
SwPageDesc* SwPageDesc::GetByName(SwDoc& rDoc, const OUString& rName)
{
- const sal_uInt16 nDCount = rDoc.GetPageDescCnt();
-
- for( sal_uInt16 i = 0; i < nDCount; i++ )
- {
- SwPageDesc* pDsc = &rDoc.GetPageDesc( i );
- if(pDsc->GetName() == rName)
- {
- return pDsc;
- }
- }
+ SwPageDesc* pDsc = rDoc.FindPageDescByName( rName );
+ if (pDsc)
+ return pDsc;
for( sal_Int32 i = RC_POOLPAGEDESC_BEGIN; i <= STR_POOLPAGE_LANDSCAPE; ++i)
{
@@ -451,7 +472,7 @@ SwPageDescExt::operator SwPageDesc() const
{
SwPageDesc aResult(aPageDesc);
- SwPageDesc * pPageDesc = pDoc->GetPageDesc(sFollow);
+ SwPageDesc * pPageDesc = pDoc->FindPageDescByName(sFollow);
if ( 0 != pPageDesc )
aResult.SetFollow(pPageDesc);
@@ -461,8 +482,83 @@ SwPageDescExt::operator SwPageDesc() const
SwPageDescs::~SwPageDescs()
{
- for(const_iterator it = begin(); it != end(); ++it)
+ DeleteAndDestroyAll();
+}
+
+void SwPageDescs::DeleteAndDestroyAll()
+{
+ for( const_iterator it = begin(); it != end(); ++it )
delete *it;
+ clear();
+}
+
+std::pair<SwPageDescs::const_iterator,bool> SwPageDescs::insert( const value_type& x )
+{
+ const_iterator const ret = find( x );
+ if (ret == end()) {
+ SwPageDescsBase::push_back( x );
+ SAL_WARN_IF(x->list == 0, "sw", "Inserting already assigned item");
+ x->list = this;
+ return std::make_pair(end() - 1 , true);
+ }
+ return std::make_pair(ret, false);
+}
+
+SwPageDescs::size_type SwPageDescs::erase( const value_type& x )
+{
+ const_iterator const ret = find( x );
+ if (ret != end()) {
+ SwPageDescsBase::erase( begin_nonconst() + (ret - begin()) );
+ x->list = 0;
+ return 1;
+ }
+ return 0;
+}
+
+void SwPageDescs::erase( size_type index )
+{
+ erase( begin_nonconst() + index );
+}
+
+void SwPageDescs::erase( const_iterator const& position )
+{
+ (*position)->list = 0;
+ SwPageDescsBase::erase( begin_nonconst() + (position - begin()) );
+}
+
+struct spd_oustring_compare : public std::unary_function<SwPageDesc*, bool>
+{
+ spd_oustring_compare(const OUString &_baseline) : baseline(_baseline) {}
+ bool operator() (SwPageDesc* const &arg)
+ { return (baseline.compareTo( arg->GetName() ) == 0); }
+ const OUString baseline;
+};
+
+struct spd_item_compare : public std::unary_function<SwPageDesc*, bool>
+{
+ spd_item_compare(const SwPageDesc* _baseline) : baseline(_baseline) {}
+ bool operator() (SwPageDesc* const &arg)
+ { return (baseline->GetName().compareTo( arg->GetName() ) == 0); }
+ const SwPageDesc* baseline;
+};
+
+SwPageDescs::const_iterator SwPageDescs::find( const OUString &name ) const
+{
+ const_iterator const it = std::find_if(
+ begin(), end(), spd_oustring_compare( name ) );
+ return it;
+}
+
+SwPageDescs::const_iterator SwPageDescs::find( const value_type& x ) const
+{
+ const_iterator const it = std::find_if(
+ begin(), end(), spd_item_compare( x ) );
+ return it;
+}
+
+bool SwPageDescs::Contains( const SwPageDescs::value_type& x ) const
+{
+ return (x->list == this);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx
index 958f510..c5dffc6 100644
--- a/sw/source/core/unocore/unosett.cxx
+++ b/sw/source/core/unocore/unosett.cxx
@@ -235,21 +235,11 @@ static SwTxtFmtColl* lcl_GetParaStyle(SwDoc* pDoc, const uno::Any& aValue)
static SwPageDesc* lcl_GetPageDesc(SwDoc* pDoc, const uno::Any& aValue)
{
- SwPageDesc* pRet = 0;
- sal_uInt16 nCount = pDoc->GetPageDescCnt();
OUString uTmp;
aValue >>= uTmp;
OUString sPageDesc;
SwStyleNameMapper::FillUIName(uTmp, sPageDesc, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, true );
- for( sal_uInt16 i = 0; i < nCount; i++)
- {
- const SwPageDesc& rDesc = pDoc->GetPageDesc( i );
- if(rDesc.GetName() == sPageDesc)
- {
- pRet = (SwPageDesc*)&rDesc;
- break;
- }
- }
+ SwPageDesc* pRet = pDoc->FindPageDescByName( sPageDesc );
if(!pRet)
{
sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(sPageDesc, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC);
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 5359ada..319aa45 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -1614,20 +1614,13 @@ const SwPageDesc& SwStyleBase_Impl::GetOldPageDesc()
{
if(!pOldPageDesc)
{
- sal_uInt16 i;
- sal_uInt16 nPDescCount = rDoc.GetPageDescCnt();
- for(i = 0; i < nPDescCount; i++)
- {
- const SwPageDesc& rDesc = rDoc.GetPageDesc( i );
- if(rDesc.GetName() == rStyleName)
- {
- pOldPageDesc = & rDesc;
- break;
- }
- }
+ SwPageDesc *pd = rDoc.FindPageDescByName( rStyleName );
+ if( pd )
+ pOldPageDesc = pd;
+
if(!pOldPageDesc)
{
- for(i = RC_POOLPAGEDESC_BEGIN; i <= STR_POOLPAGE_LANDSCAPE; ++i)
+ for(sal_uInt16 i = RC_POOLPAGEDESC_BEGIN; i <= STR_POOLPAGE_LANDSCAPE; ++i)
{
const OUString aFmtName(SW_RES(i));
if(aFmtName == rStyleName)
commit d7e4e8b4f81504e6dc7ac5964b21952debeb8d54
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date: Mon May 12 10:20:00 2014 +0200
Sorted vector special case: default first element
A lot of code using vectors in LO relies on the fact, that the
first entry in the vector contains the default value.
Therefore this adds a boolean to the constructor, which leaves
the first entry unsorted in the vector and special cases find
and insert.
All other functions are unaffected.
Change-Id: I9603f47be4fb56d991f42066ce9f5ad0ab6ffdf8
diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 3a7abe0..548c815 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -36,19 +36,44 @@ private:
typedef Find<Value, Compare> Find_t;
typedef typename std::vector<Value> base_t;
typedef typename std::vector<Value>::iterator iterator;
+ int mOffset;
+
public:
typedef typename std::vector<Value>::const_iterator const_iterator;
typedef typename std::vector<Value>::size_type size_type;
+ typedef typename std::vector<Value>::value_type value_type;
+
+private:
+ typedef typename std::pair<const_iterator, bool> find_ret_t;
+
+ find_ret_t _find( const Value& x ) const
+ {
+ if (mOffset && empty())
+ return find_ret_t(end(), false);
+ find_ret_t const ret(Find_t()(begin() + mOffset, end(), x));
+ if (!ret.second && mOffset
+ && !Compare()(x, (*this)[0]) && !Compare()((*this)[0], x))
+ return find_ret_t(begin(), true);
+ return ret;
+ }
+public:
using base_t::clear;
using base_t::empty;
using base_t::size;
+ sorted_vector(bool FirstDefault=false)
+ {
+ mOffset = FirstDefault ? 1 : 0;
+ }
+
+ int GetOffset() const { return mOffset; }
+
// MODIFIERS
std::pair<const_iterator,bool> insert( const Value& x )
{
- std::pair<const_iterator, bool> const ret(Find_t()(begin(), end(), x));
+ find_ret_t const ret = _find( x );
if (!ret.second)
{
const_iterator const it = base_t::insert(
@@ -60,7 +85,7 @@ public:
size_type erase( const Value& x )
{
- std::pair<const_iterator, bool> const ret(Find_t()(begin(), end(), x));
+ find_ret_t const ret = _find( x );
if (ret.second)
{
base_t::erase(begin_nonconst() + (ret.first - begin()));
@@ -69,7 +94,7 @@ public:
return 0;
}
- void erase( size_t index )
+ void erase( size_type index )
{
base_t::erase( begin_nonconst() + index );
}
@@ -119,14 +144,15 @@ public:
const_iterator lower_bound( const Value& x ) const
{
- return std::lower_bound( base_t::begin(), base_t::end(), x, Compare() );
+ return std::lower_bound( base_t::begin() + mOffset, base_t::end(), x, Compare() );
}
const_iterator upper_bound( const Value& x ) const
{
- return std::upper_bound( base_t::begin(), base_t::end(), x, Compare() );
+ return std::upper_bound( base_t::begin() + mOffset, base_t::end(), x, Compare() );
}
+public:
/* Searches the container for an element with a value of x
* and returns an iterator to it if found, otherwise it returns an
* iterator to sorted_vector::end (the element past the end of the container).
@@ -135,7 +161,7 @@ public:
*/
const_iterator find( const Value& x ) const
{
- std::pair<const_iterator, bool> const ret(Find_t()(begin(), end(), x));
+ find_ret_t const ret = _find( x );
return (ret.second) ? ret.first : end();
}
@@ -167,7 +193,7 @@ public:
// If you are calling this function, you are Doing It Wrong!
void Resort()
{
- std::stable_sort(begin_nonconst(), end_nonconst(), Compare());
+ std::stable_sort(begin_nonconst() + mOffset, end_nonconst(), Compare());
}
private:
diff --git a/o3tl/qa/test-sorted_vector.cxx b/o3tl/qa/test-sorted_vector.cxx
index 059c1ba..722fc34 100644
--- a/o3tl/qa/test-sorted_vector.cxx
+++ b/o3tl/qa/test-sorted_vector.cxx
@@ -248,7 +248,56 @@ public:
delete p4;
}
+ void testBasicsDefault()
+ {
+ o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent> > aVec( true );
+ SwContent *p1 = new SwContent(1);
+ SwContent *p2 = new SwContent(2);
+ SwContent *p3 = new SwContent(3);
+ SwContent *p4 = new SwContent(4);
+ SwContent *p5 = new SwContent(5);
+
+ CPPUNIT_ASSERT( aVec.insert(p3).second );
+ CPPUNIT_ASSERT( aVec.insert(p1).second );
+ CPPUNIT_ASSERT( !aVec.insert(p3).second );
+ CPPUNIT_ASSERT( aVec.insert(p5).second );
+
+ CPPUNIT_ASSERT( aVec.size() == 3 );
+
+ CPPUNIT_ASSERT( aVec[0] == p3 );
+ CPPUNIT_ASSERT( aVec[1] == p1 );
+ CPPUNIT_ASSERT( aVec[2] == p5 );
+
+ CPPUNIT_ASSERT( aVec.insert(p2).second );
+ CPPUNIT_ASSERT( aVec.size() == 4 );
+
+ CPPUNIT_ASSERT( aVec[0] == p3 );
+ CPPUNIT_ASSERT( aVec[1] == p1 );
+ CPPUNIT_ASSERT( aVec[2] == p2 );
+ CPPUNIT_ASSERT( aVec[3] == p5 );
+
+ CPPUNIT_ASSERT( *aVec.begin() == p3 );
+ CPPUNIT_ASSERT( *(aVec.end()-1) == p5 );
+
+ CPPUNIT_ASSERT( aVec.front() == p3 );
+ CPPUNIT_ASSERT( aVec.back() == p5 );
+
+ CPPUNIT_ASSERT( aVec.find(p3) != aVec.end() );
+ CPPUNIT_ASSERT( aVec.find(p3) == aVec.begin() );
+ CPPUNIT_ASSERT( aVec.find(p3) - aVec.begin() == 0 );
+ CPPUNIT_ASSERT( aVec.find(p5) != aVec.end() );
+ CPPUNIT_ASSERT( aVec.find(p5) - aVec.begin() == 3 );
+ CPPUNIT_ASSERT( aVec.find(p4) == aVec.end() );
+
+ CPPUNIT_ASSERT( aVec.erase(p3) == 1 );
+ CPPUNIT_ASSERT( aVec.find(p1) == aVec.begin() );
+ CPPUNIT_ASSERT( aVec.size() == 3 );
+ CPPUNIT_ASSERT( aVec.erase(p3) == 0 );
+
+ aVec.DeleteAndDestroyAll();
+ delete p4;
+ }
// Change the following lines only, if you add, remove or rename
// member functions of the current class,
@@ -261,6 +310,7 @@ public:
CPPUNIT_TEST(testLowerBound);
CPPUNIT_TEST(testBasics_FindPtr);
CPPUNIT_TEST(testErase_FindPtr);
+ CPPUNIT_TEST(testBasicsDefault);
CPPUNIT_TEST_SUITE_END();
};
commit 7aed3a008967a817ff3d58fb4bdf1c417fdbe8c0
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Wed May 21 17:06:08 2014 +0200
Remove spurious assert(false)
...inadvertently left over debug code
Change-Id: I4bb9ee37ee7fd5d7e4e7f91afbcc036ba5802880
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 4e7687c..3e083e2 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -2091,7 +2091,6 @@ bool PDFWriterImpl::compressStream( SvMemoryStream* pStream )
pCodec.BeginCompression();
pCodec.Write( aStream, (const sal_uInt8*)pStream->GetData(), nEndPos );
pCodec.EndCompression();
- assert(false);
nEndPos = aStream.Tell();
pStream->Seek( STREAM_SEEK_TO_BEGIN );
aStream.Seek( STREAM_SEEK_TO_BEGIN );
commit 1c92fbf4fd73a8b0ad6b79b84fa67b7e24c948a1
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Wed May 21 17:03:41 2014 +0200
Replace ZCodec::mbInit with sane enum
...and document how the member functions are supposed to be called from client
code.
Change-Id: Ia4847945e4a361c43a0ed001e3e78e901c9abcad
diff --git a/include/tools/zcodec.hxx b/include/tools/zcodec.hxx
index 5dc6723..fe13970 100644
--- a/include/tools/zcodec.hxx
+++ b/include/tools/zcodec.hxx
@@ -27,10 +27,16 @@
class SvStream;
+// The overall client call protocol is one of:
+// * BeginCompression, Compress, EndCompression
+// * BeginCompression, Decompress, EndCompression
+// * BeginCompression, Write*, EndCompression
+// * BeginCompression, Read*, EndCompression
+// * BeginCompression, ReadAsynchron*, EndCompression
class TOOLS_DLLPUBLIC ZCodec
{
-private:
- sal_uIntPtr mbInit;
+ enum State { STATE_INIT, STATE_DECOMPRESS, STATE_COMPRESS };
+ State meState;
bool mbStatus;
bool mbFinish;
SvStream* mpIStm;
diff --git a/tools/source/zcodec/zcodec.cxx b/tools/source/zcodec/zcodec.cxx
index 23abb0b..2a0b88d 100644
--- a/tools/source/zcodec/zcodec.cxx
+++ b/tools/source/zcodec/zcodec.cxx
@@ -38,7 +38,7 @@
static const int gz_magic[2] = { 0x1f, 0x8b }; /* gzip magic header */
ZCodec::ZCodec( sal_uIntPtr nInBufSize, sal_uIntPtr nOutBufSize )
- : mbInit(0)
+ : meState(STATE_INIT)
, mbStatus(false)
, mbFinish(false)
, mpIStm(NULL)
@@ -63,7 +63,7 @@ ZCodec::~ZCodec()
void ZCodec::BeginCompression( int nCompressLevel, bool updateCrc, bool gzLib )
{
- mbInit = 0;
+ assert(meState == STATE_INIT);
mbStatus = true;
mbFinish = false;
mpIStm = mpOStm = NULL;
@@ -83,9 +83,9 @@ long ZCodec::EndCompression()
{
long retvalue = 0;
- if ( mbInit != 0 )
+ if (meState != STATE_INIT)
{
- if ( mbInit & 2 ) // 1->decompress, 3->compress
+ if (meState == STATE_COMPRESS)
{
do
{
@@ -105,6 +105,7 @@ long ZCodec::EndCompression()
}
delete[] mpOutBuf;
delete[] mpInBuf;
+ meState = STATE_INIT;
}
return ( mbStatus ) ? retvalue : -1;
}
@@ -113,13 +114,11 @@ long ZCodec::Compress( SvStream& rIStm, SvStream& rOStm )
{
long nOldTotal_In = PZSTREAM->total_in;
- if ( mbInit == 0 )
- {
- mpIStm = &rIStm;
- mpOStm = &rOStm;
- ImplInitBuf( false );
- mpInBuf = new sal_uInt8[ mnInBufSize ];
- }
+ assert(meState == STATE_INIT);
+ mpIStm = &rIStm;
+ mpOStm = &rOStm;
+ ImplInitBuf( false );
+ mpInBuf = new sal_uInt8[ mnInBufSize ];
while (( PZSTREAM->avail_in = mpIStm->Read( PZSTREAM->next_in = mpInBuf, mnInBufSize )) != 0 )
{
if ( PZSTREAM->avail_out == 0 )
@@ -139,16 +138,11 @@ long ZCodec::Decompress( SvStream& rIStm, SvStream& rOStm )
sal_uIntPtr nInToRead;
long nOldTotal_Out = PZSTREAM->total_out;
- if ( mbFinish )
- return PZSTREAM->total_out - nOldTotal_Out;
-
- if ( mbInit == 0 )
- {
- mpIStm = &rIStm;
- mpOStm = &rOStm;
- ImplInitBuf( true );
- PZSTREAM->next_out = mpOutBuf = new sal_uInt8[ PZSTREAM->avail_out = mnOutBufSize ];
- }
+ assert(meState == STATE_INIT);
+ mpIStm = &rIStm;
+ mpOStm = &rOStm;
+ ImplInitBuf( true );
+ PZSTREAM->next_out = mpOutBuf = new sal_uInt8[ PZSTREAM->avail_out = mnOutBufSize ];
do
{
if ( PZSTREAM->avail_out == 0 ) ImplWriteBack();
@@ -173,14 +167,12 @@ long ZCodec::Decompress( SvStream& rIStm, SvStream& rOStm )
while ( ( err != Z_STREAM_END) && ( PZSTREAM->avail_in || mnInToRead ) );
ImplWriteBack();
- if ( err == Z_STREAM_END )
- mbFinish = true;
return ( mbStatus ) ? (long)(PZSTREAM->total_out - nOldTotal_Out) : -1;
}
long ZCodec::Write( SvStream& rOStm, const sal_uInt8* pData, sal_uIntPtr nSize )
{
- if ( mbInit == 0 )
+ if (meState == STATE_INIT)
{
mpOStm = &rOStm;
ImplInitBuf( false );
@@ -212,7 +204,7 @@ long ZCodec::Read( SvStream& rIStm, sal_uInt8* pData, sal_uIntPtr nSize )
return 0; // PZSTREAM->total_out;
mpIStm = &rIStm;
- if ( mbInit == 0 )
+ if (meState == STATE_INIT)
{
ImplInitBuf( true );
}
@@ -256,7 +248,7 @@ long ZCodec::ReadAsynchron( SvStream& rIStm, sal_uInt8* pData, sal_uIntPtr nSize
if ( mbFinish )
return 0; // PZSTREAM->total_out;
- if ( mbInit == 0 )
+ if (meState == STATE_INIT)
{
mpIStm = &rIStm;
ImplInitBuf( true );
@@ -308,7 +300,7 @@ void ZCodec::ImplWriteBack()
if ( nAvail )
{
- if ( mbInit & 2 && mbUpdateCrc )
+ if (meState == STATE_COMPRESS && mbUpdateCrc)
UpdateCRC( mpOutBuf, nAvail );
mpOStm->Write( PZSTREAM->next_out = mpOutBuf, nAvail );
PZSTREAM->avail_out = mnOutBufSize;
@@ -337,74 +329,72 @@ sal_uIntPtr ZCodec::GetCRC()
void ZCodec::ImplInitBuf ( bool nIOFlag )
{
- if ( mbInit == 0 )
+ assert(meState == STATE_INIT);
+ if ( nIOFlag )
{
- if ( nIOFlag )
+ meState = STATE_DECOMPRESS;
+ if ( mbStatus && mbGzLib )
{
- mbInit = 1;
- if ( mbStatus && mbGzLib )
+ sal_uInt8 n1, n2, j, nMethod, nFlags;
+ for ( int i = 0; i < 2; i++ ) // gz - magic number
{
- sal_uInt8 n1, n2, j, nMethod, nFlags;
- for ( int i = 0; i < 2; i++ ) // gz - magic number
- {
- mpIStm->ReadUChar( j );
- if ( j != gz_magic[ i ] )
- mbStatus = false;
- }
- mpIStm->ReadUChar( nMethod );
- mpIStm->ReadUChar( nFlags );
- if ( nMethod != Z_DEFLATED )
- mbStatus = false;
- if ( ( nFlags & GZ_RESERVED ) != 0 )
+ mpIStm->ReadUChar( j );
+ if ( j != gz_magic[ i ] )
mbStatus = false;
- /* Discard time, xflags and OS code: */
- mpIStm->SeekRel( 6 );
- /* skip the extra field */
- if ( nFlags & GZ_EXTRA_FIELD )
- {
- mpIStm->ReadUChar( n1 ).ReadUChar( n2 );
- mpIStm->SeekRel( n1 + ( n2 << 8 ) );
- }
- /* skip the original file name */
- if ( nFlags & GZ_ORIG_NAME)
- {
- do
- {
- mpIStm->ReadUChar( j );
- }
- while ( j && !mpIStm->IsEof() );
- }
- /* skip the .gz file comment */
- if ( nFlags & GZ_COMMENT )
+ }
+ mpIStm->ReadUChar( nMethod );
+ mpIStm->ReadUChar( nFlags );
+ if ( nMethod != Z_DEFLATED )
+ mbStatus = false;
+ if ( ( nFlags & GZ_RESERVED ) != 0 )
+ mbStatus = false;
+ /* Discard time, xflags and OS code: */
+ mpIStm->SeekRel( 6 );
+ /* skip the extra field */
+ if ( nFlags & GZ_EXTRA_FIELD )
+ {
+ mpIStm->ReadUChar( n1 ).ReadUChar( n2 );
+ mpIStm->SeekRel( n1 + ( n2 << 8 ) );
+ }
+ /* skip the original file name */
+ if ( nFlags & GZ_ORIG_NAME)
+ {
+ do
{
- do
- {
- mpIStm->ReadUChar( j );
- }
- while ( j && !mpIStm->IsEof() );
+ mpIStm->ReadUChar( j );
}
- /* skip the header crc */
- if ( nFlags & GZ_HEAD_CRC )
- mpIStm->SeekRel( 2 );
- if ( mbStatus )
- mbStatus = ( inflateInit2( PZSTREAM, -MAX_WBITS) != Z_OK ) ? false : true;
+ while ( j && !mpIStm->IsEof() );
}
- else
+ /* skip the .gz file comment */
+ if ( nFlags & GZ_COMMENT )
{
- mbStatus = ( inflateInit( PZSTREAM ) >= 0 );
+ do
+ {
+ mpIStm->ReadUChar( j );
+ }
+ while ( j && !mpIStm->IsEof() );
}
- mpInBuf = new sal_uInt8[ mnInBufSize ];
+ /* skip the header crc */
+ if ( nFlags & GZ_HEAD_CRC )
+ mpIStm->SeekRel( 2 );
+ if ( mbStatus )
+ mbStatus = ( inflateInit2( PZSTREAM, -MAX_WBITS) != Z_OK ) ? false : true;
}
else
{
- mbInit = 3;
+ mbStatus = ( inflateInit( PZSTREAM ) >= 0 );
+ }
+ mpInBuf = new sal_uInt8[ mnInBufSize ];
+ }
+ else
+ {
+ meState = STATE_COMPRESS;
- mbStatus = ( deflateInit2_( PZSTREAM, mnCompressLevel, Z_DEFLATED,
- MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY,
- ZLIB_VERSION, sizeof( z_stream ) ) >= 0 );
+ mbStatus = ( deflateInit2_( PZSTREAM, mnCompressLevel, Z_DEFLATED,
+ MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY,
+ ZLIB_VERSION, sizeof( z_stream ) ) >= 0 );
- PZSTREAM->next_out = mpOutBuf = new sal_uInt8[ PZSTREAM->avail_out = mnOutBufSize ];
- }
+ PZSTREAM->next_out = mpOutBuf = new sal_uInt8[ PZSTREAM->avail_out = mnOutBufSize ];
}
}
commit d4af55670fa1f2653e4a64031cc09d51b5ccc8f6
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Wed May 21 16:49:36 2014 +0200
try to fix Mac build
Change-Id: Id36f801cdf72d7654958b9d9837590990fdf161b
diff --git a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx
index fc5c8d7..2dde9d1 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx
@@ -1017,7 +1017,7 @@ DECLARE_OOXMLEXPORT_TEST(testFdo76249, "fdo76249.docx")
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
if (!pXmlDoc)
return;
- assertXPath(pXmlDoc, "//mc:Choice[2]/w:drawing[1]/wp:inline[1]/a:graphic[1]/a:graphicData[1]/lc:lockedCanvas[1]",1);
+ assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[1]/w:r[2]/mc:AlternateContent[1]/mc:Fallback[1]/w:pict[1]/v:rect[1]/v:textbox[1]/w:txbxContent[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:inline[1]/a:graphic[1]/a:graphicData[1]/lc:lockedCanvas[1]",1);
}
DECLARE_OOXMLEXPORT_TEST(testFdo76979, "fdo76979.docx")
commit 583619b77195256149cbb47d71f09b204bca7c7c
Author: Caolán McNamara <caolanm at redhat.com>
Date: Wed May 21 15:02:28 2014 +0100
don't crash on formatting outline level 10 in master view
There are only 9 outline level styles, but we are allowed
(for some nutball reason) to create 10 levels, trying
to change the format of level 10 will then crash when
trying to apply its formatting to the non-existent
underlying style
Change-Id: Ic240322f98d832bc59edb502dd6d4988aa022481
diff --git a/sd/source/ui/view/drawview.cxx b/sd/source/ui/view/drawview.cxx
index af9f4de..18a181f 100644
--- a/sd/source/ui/view/drawview.cxx
+++ b/sd/source/ui/view/drawview.cxx
@@ -197,35 +197,40 @@ bool DrawView::SetAttributes(const SfxItemSet& rSet,
OUString aName = rPage.GetLayoutName() + " " +
OUString::number((nDepth <= 0) ? 1 : nDepth + 1);
SfxStyleSheet* pSheet = (SfxStyleSheet*)pStShPool->Find(aName, SD_STYLE_FAMILY_MASTERPAGE);
- DBG_ASSERT(pSheet, "StyleSheet not found");
-
- SfxItemSet aTempSet( pSheet->GetItemSet() );
- aTempSet.Put( rSet );
- aTempSet.ClearInvalidItems();
-
- if( nDepth > 0 && aTempSet.GetItemState( EE_PARA_NUMBULLET ) == SFX_ITEM_ON )
+ //We have no stylesheet if we access outline level 10
+ //in the master preview, there is no true style backing
+ //that entry
+ SAL_WARN_IF(!pSheet, "sd", "StyleSheet " << aName << " not found");
+ if (pSheet)
{
- // no SvxNumBulletItem in outline level 1 to 8!
- aTempSet.ClearItem( EE_PARA_NUMBULLET );
- }
+ SfxItemSet aTempSet( pSheet->GetItemSet() );
+ aTempSet.Put( rSet );
+ aTempSet.ClearInvalidItems();
- // Undo-Action
- StyleSheetUndoAction* pAction = new StyleSheetUndoAction(&mrDoc, pSheet, &aTempSet);
- mpDocSh->GetUndoManager()->AddUndoAction(pAction);
+ if( nDepth > 0 && aTempSet.GetItemState( EE_PARA_NUMBULLET ) == SFX_ITEM_ON )
+ {
+ // no SvxNumBulletItem in outline level 1 to 8!
+ aTempSet.ClearItem( EE_PARA_NUMBULLET );
+ }
- pSheet->GetItemSet().Put(aTempSet);
- pSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
+ // Undo-Action
+ StyleSheetUndoAction* pAction = new StyleSheetUndoAction(&mrDoc, pSheet, &aTempSet);
+ mpDocSh->GetUndoManager()->AddUndoAction(pAction);
- // now also broadcast any child sheets
- sal_Int16 nChild;
- for( nChild = nDepth + 1; nChild < 9; nChild++ )
- {
- OUString aSheetName = rPage.GetLayoutName() + " " +
- OUString::number((nChild <= 0) ? 1 : nChild + 1);
- SfxStyleSheet* pOutlSheet = static_cast< SfxStyleSheet* >(pStShPool->Find(aSheetName, SD_STYLE_FAMILY_MASTERPAGE));
+ pSheet->GetItemSet().Put(aTempSet);
+ pSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
- if( pOutlSheet )
- pOutlSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
+ // now also broadcast any child sheets
+ sal_Int16 nChild;
+ for( nChild = nDepth + 1; nChild < 9; nChild++ )
+ {
+ OUString aSheetName = rPage.GetLayoutName() + " " +
+ OUString::number((nChild <= 0) ? 1 : nChild + 1);
+ SfxStyleSheet* pOutlSheet = static_cast< SfxStyleSheet* >(pStShPool->Find(aSheetName, SD_STYLE_FAMILY_MASTERPAGE));
+
+ if( pOutlSheet )
+ pOutlSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
+ }
}
++iter;
commit 67444a92e4168414a973e68488f84615a7d03e4d
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Wed May 21 16:21:26 2014 +0200
-Werror,-Wunused-variable
Change-Id: Ie7919740e7e95eb53f7a719e3dc2b114c6fd3862
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index d686009..d6c1dff 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -1601,7 +1601,6 @@ sal_uInt32 OpenGL3DRenderer::GetPixelColorFromPoint(long nX, long nY)
boost::scoped_array<sal_uInt8> buf(new sal_uInt8[4]);
glReadPixels(nX, nY, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, buf.get());
Color aColor(buf[3], buf[2], buf[1], buf[0]);
- static sal_Int32 i = 0;
return aColor.GetColor();
}
commit 08bc9faedbc7dc82addbb1031120093d64443d58
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Wed May 21 16:11:02 2014 +0200
remove second part of the debug output
Change-Id: Ie691746b4621a90d2b7abbfbc75367780574032f
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index e26cafe..d686009 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -1602,7 +1602,6 @@ sal_uInt32 OpenGL3DRenderer::GetPixelColorFromPoint(long nX, long nY)
glReadPixels(nX, nY, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, buf.get());
Color aColor(buf[3], buf[2], buf[1], buf[0]);
static sal_Int32 i = 0;
- OpenGLHelper::renderToFile(m_iWidth, m_iHeight, aFileName);
return aColor.GetColor();
}
commit 31e32d3624971ba7dc9e17b7c78effd6c3c59ffa
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Wed May 21 16:04:43 2014 +0200
remove debug output
Change-Id: Ib77911177ec4d2f5b1f7c7ff75db30b6104f0682
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index d248016..e26cafe 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -1602,7 +1602,6 @@ sal_uInt32 OpenGL3DRenderer::GetPixelColorFromPoint(long nX, long nY)
glReadPixels(nX, nY, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, buf.get());
Color aColor(buf[3], buf[2], buf[1], buf[0]);
static sal_Int32 i = 0;
- OUString aFileName = OUString("/home/moggi/Documents/work/shader") + OUString::number(i) + ".png";
OpenGLHelper::renderToFile(m_iWidth, m_iHeight, aFileName);
return aColor.GetColor();
}
commit 6fd54c8e34de3a24604be428fc68ea255167a88c
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date: Wed May 21 16:03:59 2014 +0200
improve the text rendering a little bit more
Change-Id: I7662b77df94c439678d17fe31e611272d1802981
diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
index 6edb68f..d9c0724 100644
--- a/chart2/source/view/main/3DChartObjects.cxx
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -75,13 +75,17 @@ Text::Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId):
Font aFont = aDevice.GetFont();
aFont.SetSize(Size(0, 96));
aFont.SetColor(COL_BLACK);
+ ::Rectangle aRect;
aDevice.SetFont(aFont);
aDevice.Erase();
- aDevice.SetOutputSizePixel(Size(160,96));
+ aDevice.GetTextBoundRect(aRect, rStr);
+ Size aSize = aRect.GetSize();
+ aSize.Height() *= 2;
+ aDevice.SetOutputSizePixel(aSize);
aDevice.SetBackground(Wallpaper(COL_TRANSPARENT));
aDevice.DrawText(Point(0,0), rStr);
- maText = BitmapEx(aDevice.GetBitmapEx(Point(0,0), Size(160,96)));
+ maText = BitmapEx(aDevice.GetBitmapEx(Point(0,0), aSize));
}
void Text::render()
commit 6e38357d5d8aee5204f8671ec7f363d769b4329c
Author: Tor Lillqvist <tml at collabora.com>
Date: Wed May 21 15:25:29 2014 +0300
Cosmetics
Change-Id: I4ad71bd3538b1d5b033802469b16dd35df5b9724
diff --git a/vcl/inc/generic/glyphcache.hxx b/vcl/inc/generic/glyphcache.hxx
index 7cd7bba..c0eb98d 100644
--- a/vcl/inc/generic/glyphcache.hxx
+++ b/vcl/inc/generic/glyphcache.hxx
@@ -20,48 +20,36 @@
#ifndef INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
#define INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
-#include <vcl/dllapi.h>
+#include <config_graphite.h>
-class GlyphCache;
-class GlyphMetric;
-class GlyphData;
-class ServerFont;
-class GlyphCachePeer;
-class ServerFontLayoutEngine;
-class ServerFontLayout;
-class ImplFontOptions;
-class PhysicalFontCollection;
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
-#include <tools/gen.hxx>
-#include <basebmp/bitmapdevice.hxx>
-#include <boost/unordered_map.hpp>
-#include <boost/unordered_set.hpp>
#include <boost/shared_ptr.hpp>
-#include <com/sun/star/i18n/XBreakIterator.hpp>
-
-namespace basegfx { class B2DPolyPolygon; }
+#include <boost/unordered_map.hpp>
-class RawBitmap;
+#include <basebmp/bitmapdevice.hxx>
+#include <com/sun/star/i18n/XBreakIterator.hpp>
+#include <tools/gen.hxx>
+#include <vcl/dllapi.h>
#include <outfont.hxx>
#include <impfont.hxx>
-
-class ServerFontLayout;
#include <sallayout.hxx>
-#include <config_graphite.h>
-#if ENABLE_GRAPHITE
+class FtFontInfo;
+class GlyphCachePeer;
+class GlyphData;
class GraphiteFaceWrapper;
-#endif
-
-#include <ft2build.h>
-#include FT_FREETYPE_H
-#include FT_GLYPH_H
-
-namespace vcl
-{
- struct FontCapabilities;
-}
+class ImplFontOptions;
+class PhysicalFontCollection;
+class RawBitmap;
+class ServerFont;
+class ServerFontLayout;
+class ServerFontLayoutEngine;
+namespace basegfx { class B2DPolyPolygon; }
+namespace vcl { struct FontCapabilities; }
class VCL_DLLPUBLIC GlyphCache
{
@@ -173,8 +161,6 @@ private:
mutable long mnLruValue;
};
-class FtFontInfo;
-
class VCL_DLLPUBLIC ServerFont
{
public:
commit 663c6800ca8789e1830ced9c93dadb84223e1c57
Author: Jan Holesovsky <kendy at collabora.com>
Date: Tue May 20 09:37:47 2014 +0200
collada2gltf: Ignore case of the extension.
Change-Id: If7f39a1a0537c561373137e6a9dcdb22b48037f0
diff --git a/avmedia/source/framework/modeltools.cxx b/avmedia/source/framework/modeltools.cxx
index 66a95b3..c3fa11e 100644
--- a/avmedia/source/framework/modeltools.cxx
+++ b/avmedia/source/framework/modeltools.cxx
@@ -148,7 +148,9 @@ bool Embed3DModel( const uno::Reference<frame::XModel>& xModel,
{
OUString sSource = rSourceURL;
#ifdef ENABLE_COLLADA2GLTF
- if (rSourceURL.endsWith(".dae") || rSourceURL.endsWith(".kmz"))
+ const bool bIsDAE = rSourceURL.endsWithIgnoreAsciiCase(".dae");
+ const bool bIsKMZ = rSourceURL.endsWithIgnoreAsciiCase(".kmz");
+ if (bIsDAE || bIsKMZ)
{
OUString sName;
::utl::LocalFileHelper::ConvertPhysicalNameToURL(::utl::TempFile::CreateTempName(), sName);
@@ -160,7 +162,7 @@ bool Embed3DModel( const uno::Reference<frame::XModel>& xModel,
std::shared_ptr <GLTF::GLTFAsset> asset(new GLTF::GLTFAsset());
asset->setInputFilePath(sSourcePath);
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list