[Libreoffice-commits] core.git: Branch 'private/jmux/indexed-pagedescs' - 410 commits - accessibility/source animations/source avmedia/inc avmedia/Library_avmediaMacAVF.mk avmedia/Library_avmedia.mk avmedia/Library_avmediaQuickTime.mk avmedia/Module_avmedia.mk avmedia/source basctl/source basegfx/inc basegfx/Library_basegfx.mk basegfx/source basic/inc basic/source bin/findunusedcode bin/fixincludeguards.sh bridges/inc bridges/source chart2/inc chart2/opengl chart2/Package_opengl.mk chart2/qa chart2/source cli_ure/source comphelper/inc comphelper/Library_comphelper.mk comphelper/source compilerplugins/clang compilerplugins/Makefile-clang.mk configure.ac connectivity/source cppcanvas/source cppuhelper/source cppu/qa crashrep/source cui/source cui/uiconfig dbaccess/inc dbaccess/source dbaccess/uiconfig dbaccess/UIConfig_dbaccess.mk desktop/source dictionaries download.lst drawinglayer/source dtrans/source dtrans/test editeng/source embeddedobj/source embeddedobj/test embedserv/source extensions/sour ce external/collada2gltf external/lcms2 external/libpng external/libxmlsec external/mdds external/Module_external.mk external/mysqlcppconn external/nss external/opencollada extras/source filter/qa filter/source forms/source formula/source fpicker/source framework/inc framework/qa framework/source .git-hooks/pre-commit helpcompiler/source helpcontent2 i18nlangtag/source i18npool/inc i18npool/Library_localedata_others.mk i18npool/source i18nutil/source idlc/source idl/inc include/comphelper include/dbaccess include/drawinglayer include/editeng include/filter include/formula include/framework include/o3tl include/oox include/osl include/rtl include/sal include/sax include/sfx2 include/svl include/svtools include/svx include/systools include/test include/tools include/unotools include/vbahelper include/vcl include/wntgcci include/wntgccx include/xmloff jurt/test jvmfwk/plugins jvmfwk/source l10ntools/inc Library_merged.mk linguistic/source lotuswordpro/source Makefile.fetch o3tl/qa odk/ config odk/docs odk/examples odk/Package_odk_headers.mk offapi/com officecfg/registry oovbaapi/ooo oox/inc oox/Library_oox.mk oox/README oox/source package/source postprocess/CustomTarget_registry.mk postprocess/qa postprocess/Rdb_services.mk pyuno/inc pyuno/source readlicense_oo/license registry/source registry/test reportbuilder/java reportdesign/inc reportdesign/Library_rpt.mk reportdesign/Library_rptui.mk reportdesign/Library_rptxml.mk reportdesign/qa reportdesign/source RepositoryExternal.mk Repository.mk rsc/inc rsc/source sal/android salhelper/test sal/inc sal/Library_sal.mk sal/osl sal/qa sal/rtl sal/textenc sal/util sal/workben sax/qa sax/source sccomp/source sc/inc sc/Library_sc.mk scp2/InstallModule_ooo.mk scp2/source sc/qa scripting/source sc/source sc/uiconfig sdext/source sd/inc sd/qa sd/source sd/uiconfig setup_native/source sfx2/inc sfx2/source shell/source slideshow/source solenv/gbuild solenv/gcc-wrappers soltools/cpp soltools/mkdepend starmath/source stoc/source s toc/test svgio/inc svgio/source svl/inc svl/Library_svl.mk svl/qa svl/source svtools/inc svtools/source svx/inc svx/source sw/inc sw/Library_sw.mk sw/qa sw/sdi sw/source sw/uiconfig test/Library_test.mk test/source testtools/source toolkit/inc toolkit/source tools/CppunitTest_tools_test.mk tools/inc tools/qa tools/source translations tubes/source ucbhelper/source ucb/source udkapi/com unotools/source unusedcode.easy uui/source vbahelper/source vcl/CppunitTest_vcl_wmf_test.mk vcl/Executable_svdemo.mk vcl/Executable_svpclient.mk vcl/Executable_svptest.mk vcl/Executable_vcldemo.mk vcl/generic vcl/inc vcl/Library_vcl.mk vcl/Module_vcl.mk vcl/osx vcl/qa vcl/quartz vcl/source vcl/unx vcl/workben winaccessibility/inc winaccessibility/source wizards/com wizards/source writerfilter/inc writerfilter/source writerperfect/source xmlhelp/source xmloff/source xmlscript/source xmlsecurity/inc xmlsecurity/source

Jan-Marek Glogowski glogow at fbihome.de
Mon May 19 00:58:39 PDT 2014


Rebased ref, commits from common ancestor:
commit 8ac69b8bc60674796f0543c8937ddf0973bd4f4f
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 b5bdc4e..5c7c338 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];
@@ -376,34 +379,16 @@ public:
     // the destructor will free all objects still in the vector
     ~SwPageDescs();
 
-    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 ); }
-
-    void DeleteAndDestroyAll();
+    const_iterator find( const value_type& x ) const;
     const_iterator find( const OUString &name ) const;
-    const_iterator find( const value_type pd ) 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 083c3ef..ba1970a 100644
--- a/sw/source/core/layout/pagedesc.cxx
+++ b/sw/source/core/layout/pagedesc.cxx
@@ -500,30 +500,20 @@ SwPageDescs::~SwPageDescs()
     DeleteAndDestroyAll();
 }
 
-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 )
+std::pair<SwPageDescs::const_iterator,bool> SwPageDescs::insert( const SwPageDescs::value_type& x )
 {
     sal_uInt16 nId = x->GetPoolFmtId();
     if (nId != USHRT_MAX && NULL != GetPoolPageDesc( nId  ))
         SAL_WARN("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) {
         SAL_WARN_IF(x->list == 0, "sw", "Inserting already assigned item");
         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 SwPageDescs::value_type& x )
@@ -539,54 +529,57 @@ void SwPageDescs::_erase( const SwPageDescs::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( SwPageDescs::size_type index )
 {
-    erase( begin_nonconst() + index );
+    erase( begin() + index );
 }
 
 void SwPageDescs::erase( SwPageDescs::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 pd ) const
+SwPageDescs::const_iterator SwPageDescs::find( const SwPageDescs::value_type& x ) const
 {
-    const_iterator const it = std::find_if(
-        begin(), end(), spd_item_compare( pd ) );
-    return it;
+    return find( x->GetName() );
 }
 
 bool SwPageDescs::Contains( const SwPageDescs::value_type &x ) const
commit 0685b8a7920e76c03ba941af2cbc4616e5fffe9b
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date:   Mon May 12 18:55:58 2014 +0200

    Fixup vector stuff (catchall)
    
    Fixup some occations of broken vector => sorted_vector stuff.
    
    There are still plenty of failures in the unit tests especially
    with ooxml import and export.
    
    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/helpcontent2 b/helpcontent2
index 37bfa7d..43d91a4 160000
--- a/helpcontent2
+++ b/helpcontent2
@@ -1 +1 @@
-Subproject commit 37bfa7d9f018d6e683df285bbf144bfe28078314
+Subproject commit 43d91a4743d30b2e4c194d991c865b7c4be7616c
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..ab8cc4c 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,6 +497,12 @@ 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)
@@ -561,14 +566,12 @@ 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 )
+    if ( pDel == maPageDescs[0] ) {
+        SAL_WARN("sw", "You cannot delete the default Pagedesc.");
         return;
-
-    SwPageDesc *pDel = maPageDescs[i];
+    }
 
     if (bBroadcast)
         BroadcastStyleOperation(pDel->GetName(), SFX_STYLE_FAMILY_PAGE,
@@ -582,11 +585,18 @@ 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." );
+    OSL_ENSURE( i != 0, "You cannot delete the default Pagedesc.");
+    DelPageDescP( maPageDescs[ i ], bBroadcast );
+}
+
 SwPageDesc* SwDoc::MakePageDesc( const OUString &rName, const SwPageDesc *pCpy,
                                  bool bRegardLanguage, bool bBroadcast)
 {
@@ -782,20 +792,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);
+}
 
-    if (FindPageDescByName(rName, &nI))
-        ChgPageDesc(nI, rDesc);
+bool SwDoc::ContainsPageDesc( const SwPageDesc *pg ) const
+{
+    return maPageDescs.Contains( const_cast<SwPageDesc*>( pg ) );
+}
+
+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 9f794b7a66a7f78ac3a233f7c99db6dcac4c3b3d
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 d97d118be0d375b34ebeb7a5803fc4b63d813120
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 65a420b..b5bdc4e 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();
 
@@ -382,6 +398,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 8cc23b4..083c3ef 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 );
+    if ( list != 0 )
+        list->SetPoolPageDesc( this, nIdOld );
+}
+
 /// 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,45 @@ 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();
+    if (nId != USHRT_MAX && NULL != GetPoolPageDesc( nId  ))
+        SAL_WARN("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");
         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 SwPageDescs::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 +555,7 @@ void SwPageDescs::erase( SwPageDescs::size_type index )
 
 void SwPageDescs::erase( SwPageDescs::const_iterator const& position )
 {
-    (*position)->list = 0;
+    _erase( *position );
     SwPageDescsBase::erase( begin_nonconst() + (position - begin()) );
 }
 
@@ -561,4 +594,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 614f27aedc7f4ac5700102b5acde41358972d446
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..65a420b 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,49 @@ 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();
+
+    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 ); }
+
+    void DeleteAndDestroyAll();
+    const_iterator find( const OUString &name ) const;
+    const_iterator find( const value_type pd ) 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..8cc23b4 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( SwPageDescs::size_type index )
+{
+    erase( begin_nonconst() + index );
+}
+
+void SwPageDescs::erase( SwPageDescs::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 pd ) const
+{
+    const_iterator const it = std::find_if(
+        begin(), end(), spd_item_compare( pd ) );
+    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 bb2172756fbd8568d97a507e7b9e98c3650ebd2f
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 86cac77fc143b85452c22b2ca06810696a0d15ed
Author: haochen <haochen at multicorewareinc.com>
Date:   Mon May 19 14:57:15 2014 +0800

    GPU Calc:Fixed compiling warning in opbase.cxx&op_math.cxx
    
    Change-Id: I885bf77a85f7f479a8a9632e64af306be243cdd0

diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 2be3146..c2a20eb 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -990,8 +990,6 @@ void OpSinh::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string &sSymName, SubArguments &vSubArguments)
 {
     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
-    static_cast<const
-              formula::SingleVectorRefToken *>(tmpCur);
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (unsigned i = 0; i < vSubArguments.size(); i++)
diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx
index 6bc5214..dfda160 100644
--- a/sc/source/core/opencl/opbase.cxx
+++ b/sc/source/core/opencl/opbase.cxx
@@ -42,7 +42,7 @@ VectorRef::VectorRef(const std::string &s, FormulaTreeNodeRef ft, int idx):
 VectorRef::~VectorRef()
 {
     if (mpClmem) {
-        cl_int ret = clReleaseMemObject(mpClmem);
+        clReleaseMemObject(mpClmem);
     }
 }
 
commit 2b0a05c7b0eeec7fc75fa80e57c51d5142446e67
Author: haochen <haochen at multicorewareinc.com>
Date:   Tue May 13 10:29:11 2014 +0800

    GPU Calc: Fix bug
    
    For arraybound  of slidingwindows parameters  in COVAR formula
    
    Change-Id: I17a601edfbc720d4e3e40fc31bf6efd73b4ac65b

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index c64588a..88541e2 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -8067,21 +8067,31 @@ void OpCovar::GenSlidingWindowFunction(std::stringstream& ss,
         size_t nCurWindowSizeY = pCurDVRY->GetRefRowSize();
         if(nCurWindowSizeX == nCurWindowSizeY)
         {
-            ss << "    for(int i = ";
+            ss << "    for( ";
             if (!pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
-                ss << "gid0; i < " << nCurWindowSizeX << "; i++) {\n";
-                ss << "        arg0 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef()<< ";\n";
-                ss << "        arg1 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
-#ifdef ISNAN
-                ss << "        if(isNan(arg0) || isNan(arg1) || (i >= ";
-                ss << pCurDVRX->GetArrayLength() << ") || (i >=";
-                ss << pCurDVRY->GetArrayLength() << ")) {\n";
+                ss << "int i = gid0; i < " << nCurWindowSizeX;
+                ss << " && i < " << pCurDVRX->GetArrayLength() << " && i < ";
+                ss << pCurDVRY->GetArrayLength() << "; i++){\n";
+#ifdef  ISNAN
+                ss << "        if(isNan(";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
+                ss << " isNan("<< vSubArguments[1]->GenSlidingWindowDeclRef();
+                ss << ")) {\n";
                 ss << "            arg0 = 0.0;\n";
                 ss << "            arg1 = 0.0;\n";
                 ss << "            --cnt;\n";
                 ss << "        }\n";
+                ss << "else{\n";
+                ss << "        arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "        arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "}\n";
+#else
+                ss << "        arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "        arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
 #endif
                 ss << "        ++cnt;\n";
                 ss << "        vSum0 += arg0;\n";
@@ -8089,19 +8099,28 @@ void OpCovar::GenSlidingWindowFunction(std::stringstream& ss,
                 ss << "    }\n";
             }
             else if (pCurDVRX->IsStartFixed() && !pCurDVRX->IsEndFixed()) {
-                ss << "0; i < gid0 + " << nCurWindowSizeX << "; i++) {\n";
-                ss << "        arg0 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "        arg1 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "int i = 0; i < gid0 + " << nCurWindowSizeX << " && ";
+                ss << " i < " << pCurDVRX->GetArrayLength() << " && ";
+                ss << " i < " << pCurDVRY->GetArrayLength() << "; i++) {\n";
 #ifdef ISNAN
-                ss << "        if(isNan(arg0) || isNan(arg1) || (i >= ";
-                ss << pCurDVRX->GetArrayLength() << ") || (i >=";
-                ss << pCurDVRY->GetArrayLength() << ")) {\n";
+                ss << "        if(isNan(";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
+                ss << " isNan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
+                ss << ")) {\n";
                 ss << "            arg0 = 0.0;\n";
                 ss << "            arg1 = 0.0;\n";
                 ss << "            --cnt;\n";
                 ss << "        }\n";
+                ss << "else{\n";
+                ss << "        arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "        arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
+#else
+                ss << "        arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef()<< ";\n";
+                ss << "        arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
 #endif
                 ss << "        ++cnt;\n";
                 ss << "        vSum0 += arg0;\n";
@@ -8109,19 +8128,28 @@ void OpCovar::GenSlidingWindowFunction(std::stringstream& ss,
                 ss << "    }\n";
             }
             else if (pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
-                ss << "0; i < " << nCurWindowSizeX << "; i++) {\n";
-                ss << "        arg0 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "        arg1 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "int i = 0; i < " << nCurWindowSizeX << " && i < ";
+                ss << pCurDVRX->GetArrayLength() << " && i < ";
+                ss << pCurDVRY->GetArrayLength() << "; i++) {\n";
 #ifdef ISNAN
-                ss << "        if(isNan(arg0) || isNan(arg1) || (i >= ";
-                ss << pCurDVRX->GetArrayLength() << ") || (i >=";
-                ss << pCurDVRY->GetArrayLength() << ")) {\n";
+                ss << "        if(isNan(";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
+                ss << " isNan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
+                ss << ")) {\n";
                 ss << "            arg0 = 0.0;\n";
                 ss << "            arg1 = 0.0;\n";
                 ss << "            --cnt;\n";
                 ss << "        }\n";
+                ss << "else{\n";
+                ss << "        arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "        arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
+#else
+                ss << "        arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "        arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
 #endif
                 ss << "        ++cnt;\n";
                 ss << "        vSum0 += arg0;\n";
@@ -8129,19 +8157,30 @@ void OpCovar::GenSlidingWindowFunction(std::stringstream& ss,
                 ss << "    }\n";
             }
             else {
-                ss << "0; i < " << nCurWindowSizeX << "; i++) {\n";
-                ss << "        arg0 = ";
-                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-                ss << "        arg1 = ";
-                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "int i = 0; i < " << nCurWindowSizeX << " && ";
+                ss << " i + gid0 < " << pCurDVRX->GetArrayLength();
+                ss << " && i + gid0 < " << pCurDVRX->GetArrayLength();
+                ss << "; i++) {\n";
 #ifdef ISNAN
-                ss << "        if(isNan(arg0) || isNan(arg1) || (i + gid0 >= ";
-                ss << pCurDVRX->GetArrayLength() << ") || (i + gid0 >=";
-                ss << pCurDVRY->GetArrayLength() << ")) {\n";
+                ss << "if ((isNan(";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ")) || ";
+                ss << "(isNan("<< vSubArguments[1]->GenSlidingWindowDeclRef();
+                ss << ")))  {\n";
                 ss << "            arg0 = 0.0;\n";
                 ss << "            arg1 = 0.0;\n";
                 ss << "            --cnt;\n";
                 ss << "        }\n";
+                ss << "        else {\n";
+                ss << "            arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "            arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "        }\n";
+#else
+                ss << "        arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "        arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
 #endif
                 ss << "        ++cnt;\n";
                 ss << "        vSum0 += arg0;\n";
@@ -8154,68 +8193,109 @@ void OpCovar::GenSlidingWindowFunction(std::stringstream& ss,
             ss << "    else {\n";
             ss << "        vMean0 = vSum0 / cnt;\n";
             ss << "        vMean1 = vSum1 / cnt;\n";
-            ss << "    for(int i = ";
+            ss << "    for(";
             if (!pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
-                ss << "gid0; i < " << nCurWindowSizeX << "; i++) {\n";
-                ss << "arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef()
-                    << ";\n";
-                ss << "arg1 = " << vSubArguments[1]->GenSlidingWindowDeclRef()
-                    << ";\n";
+                ss << "int i = gid0; i < " << nCurWindowSizeX;
+                ss << " && i < " << pCurDVRX->GetArrayLength() << " && i < ";
+                ss << pCurDVRY->GetArrayLength() << "; i++){\n";
 #ifdef ISNAN
-                ss << "        if(isNan(arg0) || isNan(arg1) || (i >= ";
-                ss << pCurDVRX->GetArrayLength() << ") || (i >=";
-                ss << pCurDVRY->GetArrayLength() << ")) {\n";
+                ss << "        if(isNan(";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
+                ss << " isNan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
+                ss << ")){\n";
                 ss << "            arg0 = vMean0;\n";
                 ss << "            arg1 = vMean1;\n";
                 ss << "        }\n";
-#endif
-                ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
-                ss << "    }\n";
-            } else if (pCurDVRX->IsStartFixed() && !pCurDVRX->IsEndFixed()) {
-                ss << "0; i < gid0 + " << nCurWindowSizeX << "; i++) {\n";
+                ss << "        else{\n";
+                ss << "            arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "            arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
+#else
                 ss << "        arg0 = ";
                 ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
                 ss << "        arg1 = ";
                 ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+#endif
+                ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
+                ss << "    }\n";
+            }
+            else if (pCurDVRX->IsStartFixed() && !pCurDVRX->IsEndFixed()) {
+                ss << "int i = 0; i < gid0 + " << nCurWindowSizeX << " && ";
+                ss << " i < " << pCurDVRX->GetArrayLength() << " && ";
+                ss << " i < " << pCurDVRY->GetArrayLength() << "; i++) {\n";
 #ifdef ISNAN
-                ss << "        if(isNan(arg0) || isNan(arg1) || (i >= ";
-                ss << pCurDVRX->GetArrayLength() << ") || (i >=";
-                ss << pCurDVRY->GetArrayLength() << ")) {\n";
+                ss << "        if(isNan(";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") || ";
+                ss << "isNan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
+                ss << ")) {\n";
                 ss << "            arg0 = vMean0;\n";
                 ss << "            arg1 = vMean1;\n";
                 ss << "        }\n";
-#endif
-                ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
-                ss << "    }\n";
-            } else if (pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
-                ss << "0; i < " << nCurWindowSizeX << "; i++) {\n";
+                ss << "else{\n";
+                ss << "        arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "        arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
+#else
                 ss << "        arg0 = ";
                 ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
                 ss << "        arg1 = ";
                 ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+#endif
+                ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
+                ss << "    }\n";
+            }
+            else if (pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
+                ss << "int i = 0; i < " << nCurWindowSizeX << " && i < ";
+                ss << pCurDVRX->GetArrayLength() << " && i < ";
+                ss << pCurDVRY->GetArrayLength() << "; i++) {\n";
 #ifdef ISNAN
-                ss << "        if(isNan(arg0) || isNan(arg1) || (i >= ";
-                ss << pCurDVRX->GetArrayLength() << ") || (i >=";
-                ss << pCurDVRY->GetArrayLength() << ")) {\n";
+                ss << "        if(isNan(";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") || ";
+                ss << "isNan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
+                ss << ")) {\n";
                 ss << "            arg0 = vMean0;\n";
                 ss << "            arg1 = vMean1;\n";
                 ss << "        }\n";
-#endif
-                ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
-                ss << "    }\n";
-            } else {
-                ss << "0; i < " << nCurWindowSizeX << "; i++) {\n";
+                ss << "else{\n";
+                ss << "        arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "        arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
+#else
                 ss << "        arg0 = ";
                 ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
                 ss << "        arg1 = ";
                 ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+#endif
+                ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
+                ss << "    }\n";
+            }
+            else {
+                ss << "int i = 0; i < " << nCurWindowSizeX << " && ";
+                ss << " i + gid0 < " << pCurDVRX->GetArrayLength();
+                ss << " && i + gid0 < " << pCurDVRX->GetArrayLength();
+                ss << "; i++) {\n";
 #ifdef ISNAN
-                ss << "        if(isNan(arg0) || isNan(arg1) || (i + gid0 >= ";
-                ss << pCurDVRX->GetArrayLength() << ") || (i + gid0 >= ";
-                ss << pCurDVRY->GetArrayLength() << ")) {\n";
+                ss << "if((isNan(";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ")) || ";
+                ss << "(isNan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
+                ss << ")))  {\n";
                 ss << "            arg0 = vMean0;\n";
                 ss << "            arg1 = vMean1;\n";
                 ss << "        }\n";
+                ss << "        else{\n";
+                ss << "            arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "            arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+                ss << "        }\n";
+#else
+                ss << "        arg0 = ";
+                ss << vSubArguments[0]->GenSlidingWindowDeclRef()<< ";\n";
+                ss << "        arg1 = ";
+                ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
 #endif
                 ss << "        vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
                 ss << "    }\n";
commit d72763ce095f0b879e5baa1713a934225ccb39f7
Author: haochen <haochen at multicorewareinc.com>
Date:   Tue May 13 10:27:30 2014 +0800

    GPU Calc: Fix bug
    
    For arraybound  of slidingwindows parameters  in Intercept formula
    
    Change-Id: I6c96073e859ef7550033e9a46e6cafb11e8bfe0a

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 6dfe344..c64588a 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -5850,121 +5850,212 @@ void OpKurt:: GenSlidingWindowFunction(std::stringstream &ss,
 void OpIntercept::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string &sSymName, SubArguments &vSubArguments)
 {
-    FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
-    assert(pCur);
-    const formula::DoubleVectorRefToken* pCurDVR =
-        static_cast<const formula::DoubleVectorRefToken *>(pCur);
-    size_t nCurWindowSize = pCurDVR->GetRefRowSize();
-    FormulaToken *pCur1 = vSubArguments[1]->GetFormulaToken();
-    assert(pCur1);
-    const formula::DoubleVectorRefToken* pCurDVR1 =
-        static_cast<const formula::DoubleVectorRefToken *>(pCur1);
-    size_t nCurWindowSize1 = pCurDVR1->GetRefRowSize();
     ss << "\ndouble " << sSymName;
-    ss << "_"<< BinFuncName() <<"( ";
+    ss << "_" << BinFuncName() << "(";
     for (unsigned i = 0; i < vSubArguments.size(); i++)
     {
         if (i)
             ss << ",";
         vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
-    ss << ") {\n";
+    ss << "){\n";
     ss << "    int gid0 = get_global_id(0);\n";
     ss << "    double fSumX = 0.0;\n";
     ss << "    double fSumY = 0.0;\n";
+    ss << "    double fMeanX = 0.0;\n";
+    ss << "    double fMeanY = 0.0;\n";
     ss << "    double fSumDeltaXDeltaY = 0.0;\n";
     ss << "    double fSumSqrDeltaX = 0.0;\n";
-    ss << "    int length="<<nCurWindowSize;
-    ss << ";\n";
-    ss << "    int length1= "<<nCurWindowSize1;
-    ss << ";\n";
-    ss << "    if(length!=length1)\n";
-    ss << "        return 0;\n";
-    ss << "    double tmp = 0;\n";
-    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    ss << "    double fCount = 0.0;\n";
+    ss << "    double argX = 0.0;\n";
+    ss << "    double argY = 0.0;\n";
+    if(vSubArguments.size() != 2)
     {
-        pCur = vSubArguments[i]->GetFormulaToken();
-        assert(pCur);
-        if (pCur->GetType() == formula::svDoubleVectorRef)
-        {
+        ss << "    return NAN;\n";
+        ss << "}\n";
+        return ;
+    }
+    FormulaToken *pCur = vSubArguments[1]->GetFormulaToken();
+    FormulaToken *pCur1 = vSubArguments[0]->GetFormulaToken();
+    assert(pCur);
+    assert(pCur1);
+    if (pCur->GetType() == formula::svDoubleVectorRef&&
+        pCur1->GetType() == formula::svDoubleVectorRef)
+    {
+        const formula::DoubleVectorRefToken* pDVR =
+            static_cast<const formula::DoubleVectorRefToken *>(pCur);
+        const formula::DoubleVectorRefToken* pDVR1 =
+            static_cast<const formula::DoubleVectorRefToken *>(pCur1);
 
+        size_t nCurWindowSize = pDVR->GetRefRowSize();
+        size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
+        size_t arrayLength = pDVR->GetArrayLength()<
+               pDVR1->GetArrayLength() ? pDVR->GetArrayLength():
+                    pDVR1->GetArrayLength();
+        if(nCurWindowSize != nCurWindowSize1)
+        {
+            ss << "    return NAN;\n";
+            ss << "}\n";
+            return ;
         }
-        else if (pCur->GetType() == formula::svSingleVectorRef)
+        ss << "    for (int i = ";
+        if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed())
+            &&(!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
         {
 #ifdef  ISNAN
-            ss << "return HUGE_VAL";
+            ss << "gid0; i < " << arrayLength;
+            ss << " && i < " << nCurWindowSize  << "; i++)\n";
+            ss << "    {\n";
+#else
+            ss << "gid0; i < " << nCurWindowSize << "; i++)\n";
+            ss << "    {\n";
 #endif
         }
-        else if (pCur->GetType() == formula::svDouble)
+        else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+            &&(pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
         {
 #ifdef  ISNAN
-            ss << "return HUGE_VAL";
+            ss << "0; i < " << arrayLength ;
+            ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
+            ss << "    {\n";
+#else
+            ss << "0; i < gid0+" << nCurWindowSize << "; i++)\n";
+            ss << "    {\n";
 #endif
         }
-    }
-    ss << "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
-    ss << "    {\n";
-    ss << "        double arg0 = ";
-    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss << ";\n";
-    ss << "        double arg1 = ";
-    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss << ";\n";
-#ifdef ISNAN
-    ss << "        if(isNan(arg0)||((gid0+i)>=";
-    ss << pCurDVR->GetArrayLength();
-    ss << "))\n";
-    ss << "        {\n";
-    ss << "            length--;\n";
-    ss << "            continue;\n";
-    ss << "        }\n";
+        else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+            &&(!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
+        {
+#ifdef  ISNAN
+            ss << "0; i + gid0 < " << arrayLength;
+            ss << " &&  i < " << nCurWindowSize << "; i++)\n";
+            ss << "    {\n";
+#else
+            ss << "0; i < " << nCurWindowSize << "; i++)\n";
+            ss << "    {\n";
 #endif
-#ifdef ISNAN
-    ss << "        if(isNan(arg1)||((gid0+i)>=";
-    ss << pCurDVR1->GetArrayLength();
-    ss << "))\n";
-    ss << "        {\n";
-    ss << "            length--;\n";
-    ss << "            continue;\n";
-    ss << "        }\n";
+        }
+        else if ((pDVR->IsStartFixed() && pDVR->IsEndFixed())
+            &&(pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
+        {
+#ifdef  ISNAN
+            ss << "0; i < " << arrayLength << "; i++)\n";
+            ss << "    {\n";
+#else
+            ss << "0; i < " << arrayLength << "; i++)\n";

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list