[Libreoffice-commits] core.git: Branch 'private/jmux/indexed-pagedescs' - 89 commits - accessibility/inc accessibility/source avmedia/Library_avmedia.mk avmedia/source basctl/source binaryurp/source bin/update_pch.sh canvas/source chart2/source connectivity/source cppuhelper/source cppu/source cui/source dbaccess/inc dbaccess/source desktop/source desktop/unx dictionaries editeng/source extensions/inc extensions/source external/coinmp external/collada2gltf external/cppunit external/freetype external/glew external/lcms2 external/openssl external/python3 filter/source forms/source formula/source fpicker/source framework/inc framework/source helpcontent2 hwpfilter/source idlc/inc idlc/source include/editeng include/formula include/framework include/o3tl include/osl include/sfx2 include/svl include/svtools include/svx include/toolkit include/vcl lotuswordpro/inc lotuswordpro/Library_lwpft.mk lotuswordpro/source o3tl/qa oox/source pyuno/source reportdesign/inc reportdesign/source RepositoryExternal.mk Repository.mk rsc/source sal/osl sal/qa scaddins/source sc/inc sc/source sd/inc sd/source sfx2/inc sfx2/source solenv/bin solenv/gbuild starmath/inc starmath/source starmath/uiconfig svl/source svtools/source svx/Executable_pixelctl.mk svx/inc svx/Module_svx.mk svx/source svx/workben sw/inc sw/qa sw/source unotools/source uui/source vcl/Library_vcl.mk vcl/source vcl/unx wizards/source writerfilter/inc writerfilter/source xmlsecurity/inc xmlsecurity/qa xmlsecurity/source
Jan-Marek Glogowski
glogow at fbihome.de
Tue May 20 09:06:33 PDT 2014
Rebased ref, commits from common ancestor:
commit b665e010361ae48bac69a029222b2283a0caa199
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 now way to directly access the indexed vector.
And since we already need 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 5a126e2..2c6d00f 100644
--- a/sw/source/core/layout/pagedesc.cxx
+++ b/sw/source/core/layout/pagedesc.cxx
@@ -502,10 +502,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 )
@@ -514,9 +512,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",
@@ -525,9 +522,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 )
@@ -543,57 +539,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 bf046e478fedf20aafb6e6da46786e555aa022a4
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
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 40193cd..b1e54d7 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)
{
@@ -782,20 +788,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..95cd047 100644
--- a/sw/source/core/frmedt/fedesc.cxx
+++ b/sw/source/core/frmedt/fedesc.cxx
@@ -41,10 +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;
+ bool bFound = (&rDesc == GetDoc()->FindPageDescByName( rDesc.GetName() ));
OSL_ENSURE( bFound, "ChgCurPageDesc with invalid descriptor." );
#endif
@@ -115,24 +112,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 +156,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 +172,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..f61317f 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,15 @@ 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)
+
+ // PageDesc "Standard"
+// rDoc.ChgPageDesc(0, rDoc.GetPageDesc(0));
+
+ // PageDescs "Convert..."
+ for (sal_uInt16 i = 0; i < rDoc.GetPageDescCnt(); ++i)
+ rDoc.ChgPageDescP( rDoc.GetPageDesc(i) );
delete pPaM, pPaM = 0;
return nErrRet;
commit 48eee52aea76a26dd58e9db23ec1f33a654ed85d
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.
This is just a cleanup patch to prepare the conversion from a
stable vector index to a sorted vector, where indices change on
insert and removal.
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 8503513..40193cd 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 500bc59..ea7796e 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 afd54937fda22661b7fb3fac770dca87d8f0efaa
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date: Wed May 14 15:03:53 2014 +0200
Optimize SwPageDesc lookup by pool id
The default pool IDs styles in the pool are very limited. To find
the actual mathiching style you have to walk the whole style list.
This introduces an additional index for these ten pool IDs.
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..5a126e2 100644
--- a/sw/source/core/layout/pagedesc.cxx
+++ b/sw/source/core/layout/pagedesc.cxx
@@ -245,6 +245,16 @@ void SwPageDesc::RegisterChange()
}
}
+void SwPageDesc::SetPoolFmtId( sal_uInt16 nId )
+{
+ sal_uInt16 nIdOld = aMaster.GetPoolFmtId();
+ if ( nId == nIdOld )
+ return;
+ aMaster.SetPoolFmtId( nId );
+ SAL_WARN_IF(list != 0 && !list->SetPoolPageDesc( this, nIdOld ), "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 +490,11 @@ SwPageDescExt::operator SwPageDesc() const
return aResult;
}
+SwPageDescs::SwPageDescs()
+{
+ memset(poolpages, 0, sizeof(value_type) * RES_POOLPAGE_SIZE);
+}
+
SwPageDescs::~SwPageDescs()
{
DeleteAndDestroyAll();
@@ -489,27 +504,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 +559,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 +598,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 b1936c3b21206d87dcf85b899f3fc6ea80b2e1f7
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date: Mon May 12 16:00:02 2014 +0200
Implement SwPageDescs like o3tl::sorted_vector API
This moves the SwPageDescs class to pagedesc.hxx and extends
it from a vector class to a o3tl::sorted_vector compatible API.
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/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..8503513 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,33 @@ 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 );
+ }
+ 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 +794,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 6978bdd..50f0d6d 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 d8c784daf88ba2eb0d1b66b9bf96f9f056381af6
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 values.
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..182214f 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -36,19 +36,45 @@ 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;
+ }
+// virtual ~sorted_vector() {}
+
+ 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 +86,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 +95,7 @@ public:
return 0;
}
- void erase( size_t index )
+ void erase( size_type index )
{
base_t::erase( begin_nonconst() + index );
}
@@ -119,14 +145,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 +162,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 +194,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 d2a19aad658cc0e8939c16b5137c15727c3cdff9
Author: sushil_shinde <sushil.shinde at synerzip.com>
Date: Thu May 15 19:22:12 2014 +0530
fdo#78654 LO was exporting corrupt docx file.
If docx file contains multiple hyperlinks in one paragraph
and one of the hyperlink contains "PAGEREF" field. End tag
for "PAGEREF" field was not exported hence it was causing
corruption in exported file.
Fixed export part of field end tags in case of "PAGEREF".
Added unit test.
Change-Id: I18a3625213bf7269e3f441859a27acc38cf6ff45
Reviewed-on: https://gerrit.libreoffice.org/9364
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>
diff --git a/sw/qa/extras/ooxmlexport/data/fdo78654.docx b/sw/qa/extras/ooxmlexport/data/fdo78654.docx
new file mode 100644
index 0000000..81d7bd0
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/fdo78654.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 67ccaae..7f3a5b7 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -3370,6 +3370,17 @@ DECLARE_OOXMLEXPORT_TEST(testFDO78384,"fdo78384.docx")
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[1]/w:rPr/w:rFonts","ascii","Wingdings");
}
+DECLARE_OOXMLEXPORT_TEST(testFDO78654 , "fdo78654.docx")
+{
+ xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+ if (!pXmlDoc)
+ return;
+ // In case of two "Hyperlink" tags in one paragraph and one of them
+ // contains "PAGEREF" field then field end tag was missing from hyperlink.
+ assertXPath ( pXmlDoc, "/w:document/w:body/w:p[2]/w:hyperlink[3]/w:r[5]/w:fldChar", "fldCharType", "end" );
+}
+
+
DECLARE_OOXMLEXPORT_TEST(testfdo78599,"fdo78599.docx")
{
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 4c6c7d0..19807f4 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -823,6 +823,8 @@ void DocxAttributeOutput::EndRun()
FSNS( XML_w, XML_fldCharType ), "separate",
FSEND );
m_pSerializer->endElementNS( XML_w, XML_r );
+ // At start of every "PAGEREF" field m_endPageRef value should be true.
+ m_endPageRef = true;
}
m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
commit c3ed5f6d3348fa2b6551d0d942632d951555a01d
Author: Tor Lillqvist <tml at collabora.com>
Date: Tue May 20 10:57:44 2014 +0300
Fail early in OpenGLContext::ImplInit() on platforms where not yet implemented
So far this code apparently has not been invoked except in the very
special use cases for which it has been developed, and which
presumably aren't such that one would come across in "normal"
LibreOffice use.
But now it gets invoked unconditionally, in some unit tests even, and
letting it call glewInit(), which calls glGetString(), without any
OpenGL context, leads to a crash. So instead, explicitly fail early on
OS X (and iOS and Android).
Change-Id: Ia4547cc1ddff1aaa0190fcdb69506ad444214b7a
diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx
index 20d9acd..0ce85cb 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -385,10 +385,19 @@ bool OpenGLContext::ImplInit()
m_aGLWin.hDC = GetDC(m_aGLWin.hWnd);
#elif defined( MACOSX )
+ SAL_INFO("vcl.opengl", "OpenGLContext not implemented yet for OS X");
+ return false;
+
#elif defined( IOS )
+ SAL_INFO("vcl.opengl", "OpenGLContext not implemented yet for iOS");
+ return false;
+
#elif defined( ANDROID )
+ SAL_INFO("vcl.opengl", "OpenGLContext not implemented yet for Android");
+ return false;
+
#elif defined( UNX )
m_aGLWin.ctx = m_aGLWin.dpy == 0 ? 0 : glXCreateContext(m_aGLWin.dpy,
m_aGLWin.vi,
commit fe39041f98b1abb3a23b43f399963487fe5b66b9
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Tue May 20 10:03:18 2014 +0200
Remove unnecessary casts
Change-Id: Iafc7727a22d657dfb6bc97ed767907cce3679364
diff --git a/sal/osl/unx/socket.c b/sal/osl/unx/socket.c
index 052ace9..d11297f 100644
--- a/sal/osl/unx/socket.c
+++ b/sal/osl/unx/socket.c
@@ -790,7 +790,7 @@ static oslHostAddr _osl_hostentToHostAddr (const struct hostent *he)
if (_osl_isFullQualifiedDomainName(he->h_name))
{
- cn= (sal_Char *)strdup(he->h_name);
+ cn= strdup(he->h_name);
OSL_ASSERT(cn);
if (cn == NULL)
return ((oslHostAddr)NULL);
@@ -887,7 +887,7 @@ oslHostAddr SAL_CALL osl_psz_createHostAddr (
if ((pszHostname == NULL) || (pAddr == NULL))
return ((oslHostAddr)NULL);
- cn = (sal_Char *) strdup(pszHostname);
+ cn = strdup(pszHostname);
OSL_ASSERT(cn);
if (cn == NULL)
return ((oslHostAddr)NULL);
diff --git a/sal/qa/rtl/ostring/rtl_str.cxx b/sal/qa/rtl/ostring/rtl_str.cxx
index 759d30e..4ba2962 100644
--- a/sal/qa/rtl/ostring/rtl_str.cxx
+++ b/sal/qa/rtl/ostring/rtl_str.cxx
@@ -711,7 +711,7 @@ namespace rtl_str
void trim_WithLength_001()
{
char const *pStr = " trim this";
- sal_Char *pStr2 = (sal_Char*)strdup(pStr);
+ sal_Char *pStr2 = strdup(pStr);
if (pStr2)
{
rtl_str_trim_WithLength( pStr2, 2 );
@@ -724,7 +724,7 @@ namespace rtl_str
void trim_WithLength_002()
{
char const *pStr = "trim this";
- sal_Char *pStr2 = (sal_Char*)strdup(pStr);
+ sal_Char *pStr2 = strdup(pStr);
if (pStr2)
{
rtl_str_trim_WithLength( pStr2, 5 );
@@ -737,7 +737,7 @@ namespace rtl_str
void trim_WithLength_003()
{
char const *pStr = " trim this";
- sal_Char *pStr2 = (sal_Char*)strdup(pStr);
+ sal_Char *pStr2 = strdup(pStr);
if (pStr2)
{
strcpy(pStr2, pStr);
@@ -751,7 +751,7 @@ namespace rtl_str
void trim_WithLength_004()
{
char const *pStr = "\r\n\t \n\r trim \n this";
- sal_Char *pStr2 = (sal_Char*)strdup(pStr);
+ sal_Char *pStr2 = strdup(pStr);
if (pStr2)
{
rtl_str_trim_WithLength( pStr2, 17 );
@@ -764,7 +764,7 @@ namespace rtl_str
void trim_WithLength_005()
{
char const *pStr = "\r\n\t \n\r trim \t this \n\r\t\t ";
- sal_Char *pStr2 = (sal_Char*)strdup(pStr);
+ sal_Char *pStr2 = strdup(pStr);
if (pStr2)
{
rtl_str_trim_WithLength( pStr2, strlen(pStr2) );
commit cd11bc699ac50af4f560ed5f2e5e7903de0898b8
Author: Arnaud Versini <arnaud.versini at gmail.com>
Date: Fri May 9 10:38:04 2014 +0200
C string usage improvment
Change-Id: I5c59f0d2d1b911ffa1ee251e0f1355d137616493
Signed-off-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/cppuhelper/source/findsofficepath.c b/cppuhelper/source/findsofficepath.c
index 1bd7368..903b91b 100644
--- a/cppuhelper/source/findsofficepath.c
+++ b/cppuhelper/source/findsofficepath.c
@@ -135,8 +135,10 @@ static char* platformSpecific()
env = getenv( PATHVARNAME );
if (env == NULL)
return NULL;
- str = (char*) malloc( strlen( env ) + 1 );
- strcpy( str, env );
+
+ str = strdup( env );
+ if (str == NULL)
+ return NULL;
/* get the tokens separated by ':' */
dir = strtok( str, PATHSEPARATOR );
@@ -145,6 +147,12 @@ static char* platformSpecific()
{
/* construct soffice file path */
file = (char*) malloc( strlen( dir ) + strlen( APPENDIX ) + 1 );
+ if (file == NULL)
+ {
+ free(str);
+ return NULL;
+ }
+
strcpy( file, dir );
strcat( file, APPENDIX );
diff --git a/desktop/unx/source/splashx.c b/desktop/unx/source/splashx.c
index 24b2152..288656c 100644
--- a/desktop/unx/source/splashx.c
+++ b/desktop/unx/source/splashx.c
@@ -582,7 +582,7 @@ static void splash_load_image( struct splash* splash, rtl_uString* pUAppPath )
pLang = ustr_to_str (pLoc->Language);
pCountry = ustr_to_str (pLoc->Country);
- nLocSize = strlen (pLang->buffer) + strlen (pCountry->buffer) + 8;
+ nLocSize = strlen (pLang->buffer) + strlen (pCountry->buffer) + 3;
pLocale = malloc (nLocSize);
pLocale[0] = '-';
strcpy (pLocale + 1, pLang->buffer);
diff --git a/hwpfilter/source/grammar.cxx b/hwpfilter/source/grammar.cxx
index be4b591..fccd75f 100644
--- a/hwpfilter/source/grammar.cxx
+++ b/hwpfilter/source/grammar.cxx
@@ -44,13 +44,6 @@ Node *top=0L;
int Node::count = 0;
-#define allocValue(x,y) \
-x = (char *)malloc( strlen(y) +1 ); \
-strcpy(x,y)
-
-#define allocChar(x,y) \
-x = (char *)malloc(2); \
-sprintf(x,"%c",y)
#ifdef PARSE_DEBUG
#define debug printf
#else
@@ -836,55 +829,55 @@ yyreduce:
switch (yyn) {
case 1:
-{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 2:
-{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 3:
-{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 4:
-{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 5:
-{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 6:
-{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 7:
-{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 8:
-{ yyval.ptr = new Node(ID_CHARACTER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_CHARACTER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 9:
-{ yyval.ptr = new Node(ID_OPERATOR); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_OPERATOR); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 10:
-{ yyval.ptr = new Node(ID_OPERATOR); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_OPERATOR); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 11:
-{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 12:
-{ yyval.ptr = new Node(ID_DELIMETER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_DELIMETER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 13:
-{ yyval.ptr = new Node(ID_DELIMETER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_DELIMETER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 14:
-{ yyval.ptr = new Node(ID_IDENTIFIER); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_IDENTIFIER); yyval.ptr->value = strdup(yyvsp[0].str); debug("Identifier : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 15:
-{ yyval.ptr = new Node(ID_CHARACTER); allocChar(yyval.ptr->value , '|'); debug("Identifier : '|'\n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_CHARACTER); yyval.ptr->value = strdup("|"); debug("Identifier : '|'\n"); nodelist.push_back(yyval.ptr); ;
break;}
case 16:
-{ yyval.ptr = new Node(ID_NUMBER); allocValue(yyval.ptr->value , yyvsp[0].dval); debug("Number : %s\n",yyvsp[0].dval); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_NUMBER); yyval.ptr->value = strdup(yyvsp[0].dval); debug("Number : %s\n",yyvsp[0].dval); nodelist.push_back(yyval.ptr); ;
break;}
case 17:
-{ yyval.ptr = new Node(ID_STRING); allocValue(yyval.ptr->value , yyvsp[0].str); debug("String : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_STRING); yyval.ptr->value = strdup(yyvsp[0].str); debug("String : %s\n",yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 18:
{ yyval.ptr = new Node(ID_PRIMARYEXPR); yyval.ptr->child = yyvsp[0].ptr; debug("PrimaryExpr\n"); nodelist.push_back(yyval.ptr); ;
@@ -893,46 +886,46 @@ case 19:
{ yyval.ptr = new Node(ID_PRIMARYEXPR); yyval.ptr->child = yyvsp[-1].ptr; yyval.ptr->next = yyvsp[0].ptr; debug("PrimaryExpr : PrimaryExpr Identifier\n"); nodelist.push_back(yyval.ptr); ;
break;}
case 20:
-{ yyval.ptr = new Node(ID_LEFT); allocChar(yyval.ptr->value , '('); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("("); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 21:
-{ yyval.ptr = new Node(ID_LEFT); allocChar(yyval.ptr->value , '['); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("["); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 22:
-{ yyval.ptr = new Node(ID_LEFT); allocChar(yyval.ptr->value , '{'); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("{"); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 23:
-{ yyval.ptr = new Node(ID_LEFT); allocChar(yyval.ptr->value , '<'); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("<"); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 24:
-{ yyval.ptr = new Node(ID_LEFT); allocChar(yyval.ptr->value , '|'); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup("|"); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 25:
-{ yyval.ptr = new Node(ID_LEFT); allocValue(yyval.ptr->value , "||"); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value =strdup("||"); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 26:
-{ yyval.ptr = new Node(ID_LEFT); allocValue(yyval.ptr->value , yyvsp[0].str); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_LEFT); yyval.ptr->value = strdup(yyvsp[0].str); debug("EQLeft \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 27:
-{ yyval.ptr = new Node(ID_RIGHT); allocChar(yyval.ptr->value , ')'); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup(")"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 28:
-{ yyval.ptr = new Node(ID_RIGHT); allocChar(yyval.ptr->value , ']'); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup("]"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 29:
-{ yyval.ptr = new Node(ID_RIGHT); allocChar(yyval.ptr->value , '}'); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup("}"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 30:
-{ yyval.ptr = new Node(ID_RIGHT); allocChar(yyval.ptr->value , '>'); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup(">"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 31:
-{ yyval.ptr = new Node(ID_RIGHT); allocChar(yyval.ptr->value , '|'); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup("|"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 32:
-{ yyval.ptr = new Node(ID_RIGHT); allocValue(yyval.ptr->value , "||"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup("||"); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 33:
-{ yyval.ptr = new Node(ID_RIGHT); allocValue(yyval.ptr->value , yyvsp[0].str); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_RIGHT); yyval.ptr->value = strdup(yyvsp[0].str); debug("EQRight \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 34:
{ yyval.ptr = new Node(ID_FENCE); yyval.ptr->child=yyvsp[-2].ptr; yyvsp[-2].ptr->next=yyvsp[-1].ptr; yyvsp[-1].ptr->next=yyvsp[0].ptr; debug("Fence \n"); nodelist.push_back(yyval.ptr); ;
@@ -971,13 +964,13 @@ case 45:
{ yyval.ptr = new Node(ID_OVER); yyval.ptr->child = yyvsp[-3].ptr; yyvsp[-3].ptr->next = yyvsp[-1].ptr; debug("OverExpr\n"); nodelist.push_back(yyval.ptr); ;
break;}
case 46:
-{ yyval.ptr = new Node(ID_ACCENTEXPR); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Accent : %s\n", yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_ACCENTEXPR); yyval.ptr->value = strdup(yyvsp[0].str); debug("Accent : %s\n", yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 47:
{ yyval.ptr = new Node(ID_ACCENTEXPR); yyval.ptr->child=yyvsp[-1].ptr; yyvsp[-1].ptr->next = yyvsp[0].ptr; debug("AccentExpr \n"); nodelist.push_back(yyval.ptr); ;
break;}
case 48:
-{ yyval.ptr = new Node(ID_DECORATIONEXPR); allocValue(yyval.ptr->value , yyvsp[0].str); debug("Decoration : %s\n", yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
+{ yyval.ptr = new Node(ID_DECORATIONEXPR); yyval.ptr->value = strdup(yyvsp[0].str); debug("Decoration : %s\n", yyvsp[0].str); nodelist.push_back(yyval.ptr); ;
break;}
case 49:
{ yyval.ptr = new Node(ID_DECORATIONEXPR); yyval.ptr->child = yyvsp[-1].ptr; yyvsp[-1].ptr->next = yyvsp[0].ptr; debug("DecorationExpr \n"); nodelist.push_back(yyval.ptr); ;
diff --git a/rsc/source/rscpp/cpp3.c b/rsc/source/rscpp/cpp3.c
index b14f4f8..40635ed 100644
--- a/rsc/source/rscpp/cpp3.c
+++ b/rsc/source/rscpp/cpp3.c
@@ -387,8 +387,7 @@ readoptions(char* filename, char*** pfargv)
*poptbuff=EOS;
if (strlen(optbuff)>0)
{
- pfa[fargc+1]=malloc(strlen(optbuff)+1);
- strcpy(pfa[fargc+1],optbuff);
+ pfa[fargc+1]=strdup(optbuff);
fargc++;
pfa[fargc+1]=0;
poptbuff=&optbuff[0];
diff --git a/sal/osl/unx/socket.c b/sal/osl/unx/socket.c
index e5b1d24..052ace9 100644
--- a/sal/osl/unx/socket.c
+++ b/sal/osl/unx/socket.c
@@ -790,12 +790,10 @@ static oslHostAddr _osl_hostentToHostAddr (const struct hostent *he)
if (_osl_isFullQualifiedDomainName(he->h_name))
{
- cn= (sal_Char *)malloc(strlen (he->h_name) + 1);
+ cn= (sal_Char *)strdup(he->h_name);
OSL_ASSERT(cn);
if (cn == NULL)
return ((oslHostAddr)NULL);
-
- strcpy(cn, he->h_name);
}
else
{
@@ -889,13 +887,11 @@ oslHostAddr SAL_CALL osl_psz_createHostAddr (
if ((pszHostname == NULL) || (pAddr == NULL))
return ((oslHostAddr)NULL);
- cn = (sal_Char *)malloc(strlen (pszHostname) + 1);
+ cn = (sal_Char *) strdup(pszHostname);
OSL_ASSERT(cn);
if (cn == NULL)
return ((oslHostAddr)NULL);
- strcpy (cn, pszHostname);
-
pHostAddr= (oslHostAddr) malloc(sizeof(struct oslHostAddrImpl));
OSL_ASSERT(pHostAddr);
if (pHostAddr == NULL)
diff --git a/sal/qa/osl/process/osl_Thread.cxx b/sal/qa/osl/process/osl_Thread.cxx
index f5f4314..1122c25 100644
--- a/sal/qa/osl/process/osl_Thread.cxx
+++ b/sal/qa/osl/process/osl_Thread.cxx
@@ -1919,10 +1919,7 @@ namespace osl_ThreadData
// at first, set the data a value
char* pc = new char[2];
char m_nData = 'm';
-// LLA: this is a copy functions only and really only for \0 terminated strings
-// m_nData is not a string, it's a character
-// strcpy(pc, &m_nData);
- memcpy(pc, &m_nData, 1);
+ pc[0] = m_nData;
pc[1] = '\0';
myThreadData.setData(pc);
diff --git a/sal/qa/rtl/ostring/rtl_str.cxx b/sal/qa/rtl/ostring/rtl_str.cxx
index 116191d..759d30e 100644
--- a/sal/qa/rtl/ostring/rtl_str.cxx
+++ b/sal/qa/rtl/ostring/rtl_str.cxx
@@ -711,10 +711,9 @@ namespace rtl_str
void trim_WithLength_001()
{
char const *pStr = " trim this";
- sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
+ sal_Char *pStr2 = (sal_Char*)strdup(pStr);
if (pStr2)
{
- strcpy(pStr2, pStr);
rtl_str_trim_WithLength( pStr2, 2 );
CPPUNIT_ASSERT_MESSAGE("string should be empty", strlen(pStr2) == 0);
@@ -725,10 +724,9 @@ namespace rtl_str
void trim_WithLength_002()
{
char const *pStr = "trim this";
- sal_Char *pStr2 = (sal_Char*)malloc(strlen(pStr) + 1);
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list