[Libreoffice-commits] core.git: sw/inc sw/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Mar 28 12:14:43 UTC 2019


 sw/inc/docary.hxx                            |    2 
 sw/source/core/crsr/crstrvl.cxx              |    4 
 sw/source/core/doc/DocumentFieldsManager.cxx |  119 +++++++++++++--------------
 sw/source/core/doc/doc.cxx                   |    6 -
 sw/source/core/doc/docfld.cxx                |    2 
 sw/source/core/doc/doclay.cxx                |    4 
 sw/source/core/edit/edfld.cxx                |   12 +-
 sw/source/core/edit/edfldexp.cxx             |    2 
 sw/source/core/fields/dbfld.cxx              |   11 +-
 sw/source/core/fields/fldlst.cxx             |    4 
 sw/source/core/unocore/unofield.cxx          |    6 -
 sw/source/core/view/viewsh.cxx               |    2 
 sw/source/filter/ww8/ww8atr.cxx              |    2 
 sw/source/ui/fldui/fldvar.cxx                |    2 
 14 files changed, 92 insertions(+), 86 deletions(-)

New commits:
commit 2b80764ec0f7c8e2c85dbca67b9cb8a2e6b2b143
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Mar 27 14:11:27 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Mar 28 13:14:11 2019 +0100

    use unique_ptr for SwFieldTypes
    
    Change-Id: Iddfc94618e70d3ca8414d526e58746720610c552
    Reviewed-on: https://gerrit.libreoffice.org/69861
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 5e4ccce81f80..d0fda5beefa8 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -301,7 +301,7 @@ public:
     void dumpAsXml(xmlTextWriterPtr pWriter) const;
 };
 
-class SwFieldTypes : public SwVectorModifyBase<SwFieldType*> {
+class SwFieldTypes : public std::vector<std::unique_ptr<SwFieldType>> {
 public:
     void dumpAsXml(xmlTextWriterPtr pWriter) const;
 };
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index 41f4cbe9f669..bf45898fd82f 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -739,7 +739,7 @@ bool SwCursorShell::MoveFieldType(
             const size_t nSize = rFieldTypes.size();
             for( size_t i=0; i < nSize; ++i )
             {
-                pFieldType = rFieldTypes[ i ];
+                pFieldType = rFieldTypes[ i ].get();
                 if ( SwFieldIds::SetExp == pFieldType->Which() )
                 {
                     ::lcl_MakeFieldLst( aSrtLst, *pFieldType, IsReadOnlyAvailable(), true );
@@ -753,7 +753,7 @@ bool SwCursorShell::MoveFieldType(
         const size_t nSize = rFieldTypes.size();
         for( size_t i=0; i < nSize; ++i )
         {
-            pFieldType = rFieldTypes[ i ];
+            pFieldType = rFieldTypes[ i ].get();
             if( nResType == pFieldType->Which() )
             {
                 ::lcl_MakeFieldLst( aSrtLst, *pFieldType, IsReadOnlyAvailable() );
diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx
index e27475de02b7..bbb8b0d03ba8 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -228,20 +228,20 @@ SwFieldType* DocumentFieldsManager::InsertFieldType(const SwFieldType &rFieldTyp
             for( ; i < nSize; ++i )
                 if( nFieldWhich == (*mpFieldTypes)[i]->Which() &&
                     rSCmp.isEqual( sFieldNm, (*mpFieldTypes)[i]->GetName() ))
-                        return (*mpFieldTypes)[i];
+                        return (*mpFieldTypes)[i].get();
         }
         break;
 
     case SwFieldIds::TableOfAuthorities:
         for( ; i < nSize; ++i )
             if( nFieldWhich == (*mpFieldTypes)[i]->Which() )
-                return (*mpFieldTypes)[i];
+                return (*mpFieldTypes)[i].get();
         break;
 
     default:
         for( i = 0; i < nSize; ++i )
             if( nFieldWhich == (*mpFieldTypes)[i]->Which() )
-                return (*mpFieldTypes)[i];
+                return (*mpFieldTypes)[i].get();
     }
 
     std::unique_ptr<SwFieldType> pNew = rFieldTyp.Copy();
@@ -270,10 +270,10 @@ SwFieldType* DocumentFieldsManager::InsertFieldType(const SwFieldType &rFieldTyp
     default: break;
     }
 
-    mpFieldTypes->insert( mpFieldTypes->begin() + nSize, pNew.release() );
+    mpFieldTypes->insert( mpFieldTypes->begin() + nSize, std::move(pNew) );
     m_rDoc.getIDocumentState().SetModified();
 
-    return (*mpFieldTypes)[ nSize ];
+    return (*mpFieldTypes)[ nSize ].get();
 }
 
 /// @returns the field type of the Doc
@@ -281,7 +281,7 @@ SwFieldType *DocumentFieldsManager::GetSysFieldType( const SwFieldIds eWhich ) c
 {
     for( SwFieldTypes::size_type i = 0; i < INIT_FLDTYPES; ++i )
         if( eWhich == (*mpFieldTypes)[i]->Which() )
-            return (*mpFieldTypes)[i];
+            return (*mpFieldTypes)[i].get();
     return nullptr;
 }
 
@@ -318,7 +318,7 @@ SwFieldType* DocumentFieldsManager::GetFieldType(
     SwFieldType* pRet = nullptr;
     for( ; i < nSize; ++i )
     {
-        SwFieldType* pFieldType = (*mpFieldTypes)[i];
+        SwFieldType* pFieldType = (*mpFieldTypes)[i].get();
 
         if (nResId == pFieldType->Which())
         {
@@ -345,7 +345,7 @@ void DocumentFieldsManager::RemoveFieldType(size_t nField)
      */
     if(nField < mpFieldTypes->size())
     {
-        SwFieldType* pTmp = (*mpFieldTypes)[nField];
+        SwFieldType* pTmp = (*mpFieldTypes)[nField].get();
 
         // JP 29.07.96: Optionally prepare FieldList for Calculator
         SwFieldIds nWhich = pTmp->Which();
@@ -376,6 +376,8 @@ void DocumentFieldsManager::RemoveFieldType(size_t nField)
             // delete field type
             delete pTmp;
         }
+        else
+            (*mpFieldTypes)[nField].release(); // DB fields are ref-counted and delete themselves
         mpFieldTypes->erase( mpFieldTypes->begin() + nField );
         m_rDoc.getIDocumentState().SetModified();
     }
@@ -387,7 +389,7 @@ void DocumentFieldsManager::UpdateFields( bool bCloseDB )
     // Call Modify() for every field type,
     // dependent SwTextField get notified ...
 
-    for( auto pFieldType : *mpFieldTypes )
+    for( auto const & pFieldType : *mpFieldTypes )
     {
         switch( pFieldType->Which() )
         {
@@ -454,8 +456,8 @@ void DocumentFieldsManager::InsDeletedFieldType( SwFieldType& rFieldTyp )
 
     for( SwFieldTypes::size_type i = INIT_FLDTYPES; i < nSize; ++i )
     {
-        SwFieldType* pFnd;
-        if( nFieldWhich == (pFnd = (*mpFieldTypes)[i])->Which() &&
+        SwFieldType* pFnd = (*mpFieldTypes)[i].get();
+        if( nFieldWhich == pFnd->Which() &&
             rSCmp.isEqual( rFieldNm, pFnd->GetName() ) )
         {
             // find new name
@@ -463,10 +465,12 @@ void DocumentFieldsManager::InsDeletedFieldType( SwFieldType& rFieldTyp )
             do {
                 OUString sSrch = rFieldNm + OUString::number( nNum );
                 for( i = INIT_FLDTYPES; i < nSize; ++i )
-                    if( nFieldWhich == (pFnd = (*mpFieldTypes)[i])->Which() &&
+                {
+                    pFnd = (*mpFieldTypes)[i].get();
+                    if( nFieldWhich == pFnd->Which() &&
                         rSCmp.isEqual( sSrch, pFnd->GetName() ) )
                         break;
-
+                }
                 if( i >= nSize )        // not found
                 {
                     const_cast<OUString&>(rFieldNm) = sSrch;
@@ -478,8 +482,8 @@ void DocumentFieldsManager::InsDeletedFieldType( SwFieldType& rFieldTyp )
         }
     }
 
-    // not found, so insert and delete flag
-    mpFieldTypes->insert( mpFieldTypes->begin() + nSize, &rFieldTyp );
+    // not found, so insert, and updated deleted flag
+    mpFieldTypes->insert( mpFieldTypes->begin() + nSize, std::unique_ptr<SwFieldType>(&rFieldTyp) );
     switch( nFieldWhich )
     {
     case SwFieldIds::SetExp:
@@ -613,7 +617,7 @@ bool DocumentFieldsManager::UpdateField(SwTextField * pDstTextField, SwField & r
 /// Update reference and table fields
 void DocumentFieldsManager::UpdateRefFields()
 {
-    for( auto pFieldType : *mpFieldTypes )
+    for( auto const & pFieldType : *mpFieldTypes )
         if( SwFieldIds::GetRef == pFieldType->Which() )
             pFieldType->ModifyNotification( nullptr, nullptr );
 }
@@ -625,7 +629,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt )
 
     SwFieldType* pFieldType(nullptr);
 
-    for (auto pFieldTypeTmp : *mpFieldTypes)
+    for (auto const & pFieldTypeTmp : *mpFieldTypes)
     {
         if( SwFieldIds::Table == pFieldTypeTmp->Which() )
         {
@@ -689,7 +693,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt )
                         pField->ChgValid( false );
                 }
             }
-            pFieldType = pFieldTypeTmp;
+            pFieldType = pFieldTypeTmp.get();
             break;
         }
     }
@@ -952,7 +956,7 @@ void DocumentFieldsManager::UpdateExpFieldsImpl(
         // process separately:
         for( auto n = mpFieldTypes->size(); n; )
         {
-            pFieldType = (*mpFieldTypes)[ --n ];
+            pFieldType = (*mpFieldTypes)[ --n ].get();
             switch( pFieldType->Which() )
             {
             case SwFieldIds::User:
@@ -1284,8 +1288,8 @@ void DocumentFieldsManager::UpdateUsrFields()
     SwCalc* pCalc = nullptr;
     for( SwFieldTypes::size_type i = INIT_FLDTYPES; i < mpFieldTypes->size(); ++i )
     {
-        const SwFieldType* pFieldType;
-        if( SwFieldIds::User == ( pFieldType = (*mpFieldTypes)[i] )->Which() )
+        const SwFieldType* pFieldType = (*mpFieldTypes)[i].get();
+        if( SwFieldIds::User == pFieldType->Which() )
         {
             if( !pCalc )
                 pCalc = new SwCalc( m_rDoc );
@@ -1335,7 +1339,7 @@ void DocumentFieldsManager::UpdatePageFields( SfxPoolItem* pMsgHint )
 {
     for( SwFieldTypes::size_type i = 0; i < INIT_FLDTYPES; ++i )
     {
-        SwFieldType* pFieldType = (*mpFieldTypes)[ i ];
+        SwFieldType* pFieldType = (*mpFieldTypes)[ i ].get();
         switch( pFieldType->Which() )
         {
         case SwFieldIds::PageNumber:
@@ -1728,7 +1732,7 @@ SwTextField * DocumentFieldsManager::GetTextFieldAtPos(const SwPosition & rPos)
 ///       optimization currently only available when no fields exist.
 bool DocumentFieldsManager::containsUpdatableFields()
 {
-    for (auto pFieldType : *mpFieldTypes)
+    for (auto const & pFieldType : *mpFieldTypes)
     {
         SwIterator<SwFormatField,SwFieldType> aIter(*pFieldType);
         if (aIter.First())
@@ -1748,48 +1752,48 @@ void DocumentFieldsManager::GCFieldTypes()
 void DocumentFieldsManager::InitFieldTypes()       // is being called by the CTOR
 {
     // Field types
-    mpFieldTypes->push_back( new SwDateTimeFieldType(&m_rDoc) );
-    mpFieldTypes->push_back( new SwChapterFieldType );
-    mpFieldTypes->push_back( new SwPageNumberFieldType );
-    mpFieldTypes->push_back( new SwAuthorFieldType );
-    mpFieldTypes->push_back( new SwFileNameFieldType(&m_rDoc) );
-    mpFieldTypes->push_back( new SwDBNameFieldType(&m_rDoc) );
-    mpFieldTypes->push_back( new SwGetExpFieldType(&m_rDoc) );
-    mpFieldTypes->push_back( new SwGetRefFieldType( &m_rDoc ) );
-    mpFieldTypes->push_back( new SwHiddenTextFieldType );
-    mpFieldTypes->push_back( new SwPostItFieldType(&m_rDoc) );
-    mpFieldTypes->push_back( new SwDocStatFieldType(&m_rDoc) );
-    mpFieldTypes->push_back( new SwDocInfoFieldType(&m_rDoc) );
-    mpFieldTypes->push_back( new SwInputFieldType( &m_rDoc ) );
-    mpFieldTypes->push_back( new SwTableFieldType( &m_rDoc ) );
-    mpFieldTypes->push_back( new SwMacroFieldType(&m_rDoc) );
-    mpFieldTypes->push_back( new SwHiddenParaFieldType );
-    mpFieldTypes->push_back( new SwDBNextSetFieldType );
-    mpFieldTypes->push_back( new SwDBNumSetFieldType );
-    mpFieldTypes->push_back( new SwDBSetNumberFieldType );
-    mpFieldTypes->push_back( new SwTemplNameFieldType(&m_rDoc) );
-    mpFieldTypes->push_back( new SwTemplNameFieldType(&m_rDoc) );
-    mpFieldTypes->push_back( new SwExtUserFieldType );
-    mpFieldTypes->push_back( new SwRefPageSetFieldType );
-    mpFieldTypes->push_back( new SwRefPageGetFieldType( &m_rDoc ) );
-    mpFieldTypes->push_back( new SwJumpEditFieldType( &m_rDoc ) );
-    mpFieldTypes->push_back( new SwScriptFieldType( &m_rDoc ) );
-    mpFieldTypes->push_back( new SwCombinedCharFieldType );
-    mpFieldTypes->push_back( new SwDropDownFieldType );
+    mpFieldTypes->emplace_back( new SwDateTimeFieldType(&m_rDoc) );
+    mpFieldTypes->emplace_back( new SwChapterFieldType );
+    mpFieldTypes->emplace_back( new SwPageNumberFieldType );
+    mpFieldTypes->emplace_back( new SwAuthorFieldType );
+    mpFieldTypes->emplace_back( new SwFileNameFieldType(&m_rDoc) );
+    mpFieldTypes->emplace_back( new SwDBNameFieldType(&m_rDoc) );
+    mpFieldTypes->emplace_back( new SwGetExpFieldType(&m_rDoc) );
+    mpFieldTypes->emplace_back( new SwGetRefFieldType( &m_rDoc ) );
+    mpFieldTypes->emplace_back( new SwHiddenTextFieldType );
+    mpFieldTypes->emplace_back( new SwPostItFieldType(&m_rDoc) );
+    mpFieldTypes->emplace_back( new SwDocStatFieldType(&m_rDoc) );
+    mpFieldTypes->emplace_back( new SwDocInfoFieldType(&m_rDoc) );
+    mpFieldTypes->emplace_back( new SwInputFieldType( &m_rDoc ) );
+    mpFieldTypes->emplace_back( new SwTableFieldType( &m_rDoc ) );
+    mpFieldTypes->emplace_back( new SwMacroFieldType(&m_rDoc) );
+    mpFieldTypes->emplace_back( new SwHiddenParaFieldType );
+    mpFieldTypes->emplace_back( new SwDBNextSetFieldType );
+    mpFieldTypes->emplace_back( new SwDBNumSetFieldType );
+    mpFieldTypes->emplace_back( new SwDBSetNumberFieldType );
+    mpFieldTypes->emplace_back( new SwTemplNameFieldType(&m_rDoc) );
+    mpFieldTypes->emplace_back( new SwTemplNameFieldType(&m_rDoc) );
+    mpFieldTypes->emplace_back( new SwExtUserFieldType );
+    mpFieldTypes->emplace_back( new SwRefPageSetFieldType );
+    mpFieldTypes->emplace_back( new SwRefPageGetFieldType( &m_rDoc ) );
+    mpFieldTypes->emplace_back( new SwJumpEditFieldType( &m_rDoc ) );
+    mpFieldTypes->emplace_back( new SwScriptFieldType( &m_rDoc ) );
+    mpFieldTypes->emplace_back( new SwCombinedCharFieldType );
+    mpFieldTypes->emplace_back( new SwDropDownFieldType );
 
     // Types have to be at the end!
     // We expect this in the InsertFieldType!
     // MIB 14.04.95: In Sw3StringPool::Setup (sw3imp.cxx) and
     //               lcl_sw3io_InSetExpField (sw3field.cxx) now also
-    mpFieldTypes->push_back( new SwSetExpFieldType(&m_rDoc,
+    mpFieldTypes->emplace_back( new SwSetExpFieldType(&m_rDoc,
                 SwResId(STR_POOLCOLL_LABEL_ABB), nsSwGetSetExpType::GSE_SEQ) );
-    mpFieldTypes->push_back( new SwSetExpFieldType(&m_rDoc,
+    mpFieldTypes->emplace_back( new SwSetExpFieldType(&m_rDoc,
                 SwResId(STR_POOLCOLL_LABEL_TABLE), nsSwGetSetExpType::GSE_SEQ) );
-    mpFieldTypes->push_back( new SwSetExpFieldType(&m_rDoc,
+    mpFieldTypes->emplace_back( new SwSetExpFieldType(&m_rDoc,
                 SwResId(STR_POOLCOLL_LABEL_FRAME), nsSwGetSetExpType::GSE_SEQ) );
-    mpFieldTypes->push_back( new SwSetExpFieldType(&m_rDoc,
+    mpFieldTypes->emplace_back( new SwSetExpFieldType(&m_rDoc,
                 SwResId(STR_POOLCOLL_LABEL_DRAWING), nsSwGetSetExpType::GSE_SEQ) );
-    mpFieldTypes->push_back( new SwSetExpFieldType(&m_rDoc,
+    mpFieldTypes->emplace_back( new SwSetExpFieldType(&m_rDoc,
                 SwResId(STR_POOLCOLL_LABEL_FIGURE), nsSwGetSetExpType::GSE_SEQ) );
 
     assert( mpFieldTypes->size() == INIT_FLDTYPES );
@@ -1797,9 +1801,6 @@ void DocumentFieldsManager::InitFieldTypes()       // is being called by the CTO
 
 void DocumentFieldsManager::ClearFieldTypes()
 {
-    for(SwFieldTypes::const_iterator it = mpFieldTypes->begin() + INIT_FLDTYPES;
-        it != mpFieldTypes->end(); ++it)
-        delete *it;
     mpFieldTypes->erase( mpFieldTypes->begin() + INIT_FLDTYPES, mpFieldTypes->end() );
 }
 
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index d25cf80ad5fc..e39564cc2dca 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1418,10 +1418,10 @@ bool SwDoc::RemoveInvisibleContent()
         // document's field types, invalidating iterators. So, we need to create own list of
         // matching types prior to processing them.
         std::vector<std::unique_ptr<FieldTypeGuard>> aHidingFieldTypes;
-        for (SwFieldType* pType : *getIDocumentFieldsAccess().GetFieldTypes())
+        for (std::unique_ptr<SwFieldType> const & pType : *getIDocumentFieldsAccess().GetFieldTypes())
         {
             if (FieldCanHideParaWeight(pType->Which()))
-                aHidingFieldTypes.push_back(std::make_unique<FieldTypeGuard>(pType));
+                aHidingFieldTypes.push_back(std::make_unique<FieldTypeGuard>(pType.get()));
         }
         for (const auto& pTypeGuard : aHidingFieldTypes)
         {
@@ -1600,7 +1600,7 @@ bool SwDoc::ConvertFieldsToText(SwRootFrame const& rLayout)
     //go backward, field types are removed
     for(SwFieldTypes::size_type nType = nCount; nType > 0; --nType)
     {
-        const SwFieldType *pCurType = (*pMyFieldTypes)[nType - 1];
+        const SwFieldType *pCurType = (*pMyFieldTypes)[nType - 1].get();
 
         if ( SwFieldIds::Postit == pCurType->Which() )
             continue;
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index 02b81afd2340..f9327a782996 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -754,7 +754,7 @@ void SwDoc::ChangeAuthorityData( const SwAuthEntry* pNewData )
 
     for( SwFieldTypes::size_type i = INIT_FLDTYPES; i < nSize; ++i )
     {
-        SwFieldType* pFieldType = (*getIDocumentFieldsAccess().GetFieldTypes())[i];
+        SwFieldType* pFieldType = (*getIDocumentFieldsAccess().GetFieldTypes())[i].get();
         if( SwFieldIds::TableOfAuthorities  == pFieldType->Which() )
         {
             SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(pFieldType);
diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx
index 200b46592426..30bd3d0e7225 100644
--- a/sw/source/core/doc/doclay.cxx
+++ b/sw/source/core/doc/doclay.cxx
@@ -653,7 +653,7 @@ lcl_InsertLabel(SwDoc & rDoc, SwTextFormatColls *const pTextFormatCollTable,
     // Get the field first, because we retrieve the TextColl via the field's name
     OSL_ENSURE( nId == USHRT_MAX  || nId < rDoc.getIDocumentFieldsAccess().GetFieldTypes()->size(),
             "FieldType index out of bounds." );
-    SwFieldType *pType = (nId != USHRT_MAX) ? (*rDoc.getIDocumentFieldsAccess().GetFieldTypes())[nId] : nullptr;
+    SwFieldType *pType = (nId != USHRT_MAX) ? (*rDoc.getIDocumentFieldsAccess().GetFieldTypes())[nId].get() : nullptr;
     OSL_ENSURE(!pType || pType->Which() == SwFieldIds::SetExp, "wrong Id for Label");
 
     SwTextFormatColl * pColl = nullptr;
@@ -1016,7 +1016,7 @@ lcl_InsertDrawLabel( SwDoc & rDoc, SwTextFormatColls *const pTextFormatCollTable
     // Because we get by the TextColl's name, we need to create the field first.
     OSL_ENSURE( nId == USHRT_MAX  || nId < rDoc.getIDocumentFieldsAccess().GetFieldTypes()->size(),
             "FieldType index out of bounds" );
-    SwFieldType *pType = nId != USHRT_MAX ? (*rDoc.getIDocumentFieldsAccess().GetFieldTypes())[nId] : nullptr;
+    SwFieldType *pType = nId != USHRT_MAX ? (*rDoc.getIDocumentFieldsAccess().GetFieldTypes())[nId].get() : nullptr;
     OSL_ENSURE( !pType || pType->Which() == SwFieldIds::SetExp, "Wrong label id" );
 
     SwTextFormatColl *pColl = nullptr;
diff --git a/sw/source/core/edit/edfld.cxx b/sw/source/core/edit/edfld.cxx
index 26baa3e14e79..787eb13c02a6 100644
--- a/sw/source/core/edit/edfld.cxx
+++ b/sw/source/core/edit/edfld.cxx
@@ -55,7 +55,7 @@ size_t SwEditShell::GetFieldTypeCount(SwFieldIds nResId ) const
 
     // all types with the same ResId
     size_t nIdx  = 0;
-    for(const auto pFieldType : *pFieldTypes)
+    for(const auto & pFieldType : *pFieldTypes)
     {
         // same ResId -> increment index
         if(pFieldType->Which() == nResId)
@@ -71,17 +71,17 @@ SwFieldType* SwEditShell::GetFieldType(size_t nField, SwFieldIds nResId ) const
 
     if(nResId == SwFieldIds::Unknown && nField < pFieldTypes->size())
     {
-        return (*pFieldTypes)[nField];
+        return (*pFieldTypes)[nField].get();
     }
 
     size_t nIdx = 0;
-    for(const auto pFieldType : *pFieldTypes)
+    for(const auto & pFieldType : *pFieldTypes)
     {
         // same ResId -> increment index
         if(pFieldType->Which() == nResId)
         {
             if(nIdx == nField)
-                return pFieldType;
+                return pFieldType.get();
             nIdx++;
         }
     }
@@ -112,7 +112,7 @@ void SwEditShell::RemoveFieldType(SwFieldIds nResId, const OUString& rStr)
     for(SwFieldTypes::size_type i = 0; i < nSize; ++i)
     {
         // same ResId -> increment index
-        SwFieldType* pFieldType = (*pFieldTypes)[i];
+        SwFieldType* pFieldType = (*pFieldTypes)[i].get();
         if( pFieldType->Which() == nResId )
         {
             if( aTmp == rCC.lowercase( pFieldType->GetName() ) )
@@ -397,7 +397,7 @@ void SwEditShell::ChangeAuthorityData(const SwAuthEntry* pNewData)
 bool SwEditShell::IsAnyDatabaseFieldInDoc()const
 {
     const SwFieldTypes * pFieldTypes = GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
-    for(const auto pFieldType : *pFieldTypes)
+    for(const auto & pFieldType : *pFieldTypes)
     {
         if(IsUsed(*pFieldType))
         {
diff --git a/sw/source/core/edit/edfldexp.cxx b/sw/source/core/edit/edfldexp.cxx
index 946be7dd3354..91d573c4dcd7 100644
--- a/sw/source/core/edit/edfldexp.cxx
+++ b/sw/source/core/edit/edfldexp.cxx
@@ -38,7 +38,7 @@ bool SwEditShell::IsFieldDataSourceAvailable(OUString& rUsedDataSource) const
     const SwFieldTypes * pFieldTypes = GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
     uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
     uno::Reference<sdb::XDatabaseContext> xDBContext = sdb::DatabaseContext::create(xContext);
-    for(const auto pFieldType : *pFieldTypes)
+    for(const auto & pFieldType : *pFieldTypes)
     {
         if(IsUsed(*pFieldType) && pFieldType->Which() == SwFieldIds::Database)
         {
diff --git a/sw/source/core/fields/dbfld.cxx b/sw/source/core/fields/dbfld.cxx
index cba8ed87cae7..2cf0f3c181c9 100644
--- a/sw/source/core/fields/dbfld.cxx
+++ b/sw/source/core/fields/dbfld.cxx
@@ -89,9 +89,14 @@ void SwDBFieldType::ReleaseRef()
 
     if (--m_nRefCnt <= 0)
     {
-        size_t nPos = GetDoc()->getIDocumentFieldsAccess().GetFieldTypes()->GetPos(this);
-
-        if (nPos != SIZE_MAX)
+        size_t nPos = 0;
+        for (auto const & pFieldType : *GetDoc()->getIDocumentFieldsAccess().GetFieldTypes())
+        {
+            if (pFieldType.get() == this)
+                break;
+            ++nPos;
+        }
+        if (nPos < GetDoc()->getIDocumentFieldsAccess().GetFieldTypes()->size())
         {
             GetDoc()->getIDocumentFieldsAccess().RemoveFieldType(nPos);
             delete this;
diff --git a/sw/source/core/fields/fldlst.cxx b/sw/source/core/fields/fldlst.cxx
index 7fe54296de73..e967daa38fe7 100644
--- a/sw/source/core/fields/fldlst.cxx
+++ b/sw/source/core/fields/fldlst.cxx
@@ -46,7 +46,7 @@ SwInputFieldList::SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst )
     // iterate over all types
     for(size_t i=0; i < nSize; ++i)
     {
-        SwFieldType* pFieldType = rFieldTypes[ i ];
+        SwFieldType* pFieldType = rFieldTypes[ i ].get();
         const SwFieldIds nType = pFieldType->Which();
 
         if( SwFieldIds::SetExp == nType || SwFieldIds::Input == nType || SwFieldIds::Dropdown == nType )
@@ -133,7 +133,7 @@ bool SwInputFieldList::BuildSortLst()
     // iterate over all types
     for( size_t i = 0; i < nSize; ++i )
     {
-        SwFieldType* pFieldType = rFieldTypes[ i ];
+        SwFieldType* pFieldType = rFieldTypes[ i ].get();
         const SwFieldIds nType = pFieldType->Which();
 
         if( SwFieldIds::SetExp == nType || SwFieldIds::Input == nType )
diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx
index 17421871019a..439a387488a9 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -988,7 +988,7 @@ void SAL_CALL SwXFieldMaster::dispose()
     const SwFieldTypes* pTypes = m_pImpl->m_pDoc->getIDocumentFieldsAccess().GetFieldTypes();
     for( size_t i = 0; i < pTypes->size(); i++ )
     {
-        if((*pTypes)[i] == pFieldType)
+        if((*pTypes)[i].get()== pFieldType)
             nTypeIdx = i;
     }
 
@@ -1046,7 +1046,7 @@ OUString SwXFieldMaster::GetProgrammaticName(const SwFieldType& rType, SwDoc& rD
         const SwFieldTypes* pTypes = rDoc.getIDocumentFieldsAccess().GetFieldTypes();
         for( size_t i = 0; i <= size_t(INIT_FLDTYPES); i++ )
         {
-            if((*pTypes)[i] == &rType)
+            if((*pTypes)[i].get() == &rType)
             {
                 return SwStyleNameMapper::GetProgName( sName, SwGetPoolIdFromName::TxtColl );
             }
@@ -2948,7 +2948,7 @@ SwXFieldEnumeration::SwXFieldEnumeration(SwDoc & rDoc)
     const size_t nCount = pFieldTypes->size();
     for(size_t nType = 0;  nType < nCount;  ++nType)
     {
-        const SwFieldType *pCurType = (*pFieldTypes)[nType];
+        const SwFieldType *pCurType = (*pFieldTypes)[nType].get();
         SwIterator<SwFormatField,SwFieldType> aIter( *pCurType );
         const SwFormatField* pCurFieldFormat = aIter.First();
         while (pCurFieldFormat)
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index 65b45e90379d..4cf762870e2d 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -946,7 +946,7 @@ void SwViewShell::SetEmptyDbFieldHidesPara(bool bEmptyDbFieldHidesPara)
         rIDSA.set(DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA, bEmptyDbFieldHidesPara);
         StartAction();
         GetDoc()->getIDocumentState().SetModified();
-        for (auto* pFieldType : *GetDoc()->getIDocumentFieldsAccess().GetFieldTypes())
+        for (auto const & pFieldType : *GetDoc()->getIDocumentFieldsAccess().GetFieldTypes())
         {
             if (pFieldType->Which() == SwFieldIds::Database)
             {
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index abbbd8922c08..889e6ce17d9d 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -2008,7 +2008,7 @@ void AttributeOutputBase::GenerateBookmarksForSequenceField(const SwTextNode& rN
                     bool bHaveCaptionOnlyBkm = false;
                     bool bHaveNumberOnlyBkm = false;
                     bool bRunSplittedAtSep = false;
-                    for( auto pFieldType : *pFieldTypes )
+                    for( auto const & pFieldType : *pFieldTypes )
                     {
                         if( SwFieldIds::GetRef == pFieldType->Which() )
                         {
diff --git a/sw/source/ui/fldui/fldvar.cxx b/sw/source/ui/fldui/fldvar.cxx
index 5d2c264033b7..e13425597e07 100644
--- a/sw/source/ui/fldui/fldvar.cxx
+++ b/sw/source/ui/fldui/fldvar.cxx
@@ -881,7 +881,7 @@ IMPL_LINK_NOARG(SwFieldVarPage, ModifyHdl, weld::Entry&, void)
 
                     for (i = 0; i < INIT_FLDTYPES; i++)
                     {
-                        SwFieldType* pType = (*p)[ i ];
+                        SwFieldType* pType = (*p)[ i ].get();
                         if (pType == pFieldType)
                             break;
                     }


More information about the Libreoffice-commits mailing list