diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-19 14:42:42 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-20 07:45:13 +0100 |
commit | 58e798c366ba2381a0bf6422036bebe9763035a6 (patch) | |
tree | f006bbbdf2ca54d8285f867294117caa48b44df5 /sw/source | |
parent | 2068e1a556af412f77fe88a6765e50d326d225c7 (diff) |
loplugin:useuniqueptr in SwCalc
update the table to use a template, which gets rid of lots of casting
Change-Id: Ic9ed3901a33e1cd1a1d4335a704d0dd91a5c2f8a
Reviewed-on: https://gerrit.libreoffice.org/51414
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/bastyp/calc.cxx | 109 | ||||
-rw-r--r-- | sw/source/core/doc/DocumentFieldsManager.cxx | 59 | ||||
-rw-r--r-- | sw/source/core/doc/docfld.cxx | 13 | ||||
-rw-r--r-- | sw/source/core/edit/editsh.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/fields/expfld.cxx | 8 | ||||
-rw-r--r-- | sw/source/core/inc/DocumentFieldsManager.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/inc/docfld.hxx | 6 |
7 files changed, 79 insertions, 120 deletions
diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx index 2952244fd88c..c1cbfdfb841d 100644 --- a/sw/source/core/bastyp/calc.cxx +++ b/sw/source/core/bastyp/calc.cxx @@ -180,29 +180,6 @@ CalcOp* FindOperator( const OUString& rSrch ) OperatorCompare )); } -SwHash* Find( const OUString& rStr, SwHash* const * ppTable, - sal_uInt16 nTableSize, sal_uInt16* pPos ) -{ - sal_uLong ii = 0; - for( sal_Int32 n = 0; n < rStr.getLength(); ++n ) - { - ii = ii << 1 ^ rStr[n]; - } - ii %= nTableSize; - - if( pPos ) - *pPos = static_cast<sal_uInt16>(ii); - - for( SwHash* pEntry = *(ppTable+ii); pEntry; pEntry = pEntry->pNext.get() ) - { - if( rStr == pEntry->aStr ) - { - return pEntry; - } - } - return nullptr; -} - inline LanguageType GetDocAppScriptLang( SwDoc const & rDoc ) { return static_cast<const SvxLanguageItem&>(rDoc.GetDefault( @@ -225,7 +202,8 @@ static double lcl_ConvertToDateValue( SwDoc& rDoc, sal_Int32 nDate ) } SwCalc::SwCalc( SwDoc& rD ) - : m_aErrExpr( OUString(), SwSbxValue(), nullptr ) + : m_aVarTable(TBLSZ) + , m_aErrExpr( OUString(), SwSbxValue(), nullptr ) , m_nCommandPos(0) , m_rDoc( rD ) , m_pLocaleDataWrapper( m_aSysLocale.GetLocaleDataPtr() ) @@ -236,7 +214,6 @@ SwCalc::SwCalc( SwDoc& rD ) , m_eError( SwCalcError::NONE ) { m_aErrExpr.aStr = "~C_ERR~"; - memset( m_aVarTable, 0, sizeof(m_aVarTable) ); LanguageType eLang = GetDocAppScriptLang( m_rDoc ); if( eLang != m_pLocaleDataWrapper->getLanguageTag().getLanguageType() || @@ -328,27 +305,27 @@ SwCalc::SwCalc( SwDoc& rD ) for( n = 0; n < 25; ++n ) { sTmpStr = OUString::createFromAscii(sNTypeTab[n]); - m_aVarTable[ aHashValue[ n ] ] = new SwCalcExp( sTmpStr, nVal, nullptr ); + m_aVarTable[ aHashValue[ n ] ].reset( new SwCalcExp( sTmpStr, nVal, nullptr ) ); } - static_cast<SwCalcExp*>(m_aVarTable[ aHashValue[ 0 ] ])->nValue.PutBool( false ); - static_cast<SwCalcExp*>(m_aVarTable[ aHashValue[ 1 ] ])->nValue.PutBool( true ); - static_cast<SwCalcExp*>(m_aVarTable[ aHashValue[ 2 ] ])->nValue.PutDouble( F_PI ); - static_cast<SwCalcExp*>(m_aVarTable[ aHashValue[ 3 ] ])->nValue.PutDouble( 2.7182818284590452354 ); + m_aVarTable[ aHashValue[ 0 ] ]->nValue.PutBool( false ); + m_aVarTable[ aHashValue[ 1 ] ]->nValue.PutBool( true ); + m_aVarTable[ aHashValue[ 2 ] ]->nValue.PutDouble( F_PI ); + m_aVarTable[ aHashValue[ 3 ] ]->nValue.PutDouble( 2.7182818284590452354 ); for( n = 0; n < 3; ++n ) - static_cast<SwCalcExp*>(m_aVarTable[ aHashValue[ n + 4 ] ])->nValue.PutLong( rDocStat.*aDocStat1[ n ] ); + m_aVarTable[ aHashValue[ n + 4 ] ]->nValue.PutLong( rDocStat.*aDocStat1[ n ] ); for( n = 0; n < 4; ++n ) - static_cast<SwCalcExp*>(m_aVarTable[ aHashValue[ n + 7 ] ])->nValue.PutLong( rDocStat.*aDocStat2[ n ] ); + m_aVarTable[ aHashValue[ n + 7 ] ]->nValue.PutLong( rDocStat.*aDocStat2[ n ] ); SvtUserOptions& rUserOptions = SW_MOD()->GetUserOptions(); - static_cast<SwCalcExp*>(m_aVarTable[ aHashValue[ 11 ] ])->nValue.PutString( rUserOptions.GetFirstName() ); - static_cast<SwCalcExp*>(m_aVarTable[ aHashValue[ 12 ] ])->nValue.PutString( rUserOptions.GetLastName() ); - static_cast<SwCalcExp*>(m_aVarTable[ aHashValue[ 13 ] ])->nValue.PutString( rUserOptions.GetID() ); + m_aVarTable[ aHashValue[ 11 ] ]->nValue.PutString( rUserOptions.GetFirstName() ); + m_aVarTable[ aHashValue[ 12 ] ]->nValue.PutString( rUserOptions.GetLastName() ); + m_aVarTable[ aHashValue[ 13 ] ]->nValue.PutString( rUserOptions.GetID() ); for( n = 0; n < 11; ++n ) - static_cast<SwCalcExp*>(m_aVarTable[ aHashValue[ n + 14 ] ])->nValue.PutString( + m_aVarTable[ aHashValue[ n + 14 ] ]->nValue.PutString( rUserOptions.GetToken( aAdrToken[ n ] )); nVal.PutString( rUserOptions.GetToken( aAdrToken[ 11 ] )); @@ -359,9 +336,6 @@ SwCalc::SwCalc( SwDoc& rD ) SwCalc::~SwCalc() { - for(SwHash* p : m_aVarTable) - delete p; - if( m_pLocaleDataWrapper != m_aSysLocale.GetLocaleDataPtr() ) delete m_pLocaleDataWrapper; if( m_pCharClass != &GetAppCharClass() ) @@ -436,21 +410,21 @@ SwCalcExp* SwCalc::VarLook( const OUString& rStr, bool bIns ) sal_uInt16 ii = 0; OUString aStr = m_pCharClass->lowercase( rStr ); - SwHash* pFnd = Find( aStr, m_aVarTable, TBLSZ, &ii ); + SwCalcExp* pFnd = m_aVarTable.Find(aStr, &ii); if( !pFnd ) { // then check doc - SwHash* const * ppDocTable = m_rDoc.getIDocumentFieldsAccess().GetUpdateFields().GetFieldTypeTable(); - for( SwHash* pEntry = *(ppDocTable+ii); pEntry; pEntry = pEntry->pNext.get() ) + SwHashTable<SwCalcFieldType> const & rDocTable = m_rDoc.getIDocumentFieldsAccess().GetUpdateFields().GetFieldTypeTable(); + for( SwHash* pEntry = rDocTable[ii].get(); pEntry; pEntry = pEntry->pNext.get() ) { if( aStr == pEntry->aStr ) { // then insert here pFnd = new SwCalcExp( aStr, SwSbxValue(), static_cast<SwCalcFieldType*>(pEntry)->pFieldType ); - pFnd->pNext.reset( *(m_aVarTable+ii) ); - *(m_aVarTable+ii) = pFnd; + pFnd->pNext = std::move( m_aVarTable[ii] ); + m_aVarTable[ii].reset(pFnd); break; } } @@ -458,14 +432,12 @@ SwCalcExp* SwCalc::VarLook( const OUString& rStr, bool bIns ) if( pFnd ) { - SwCalcExp* pFndExp = static_cast<SwCalcExp*>(pFnd); - - if( pFndExp->pFieldType && pFndExp->pFieldType->Which() == SwFieldIds::User ) + if( pFnd->pFieldType && pFnd->pFieldType->Which() == SwFieldIds::User ) { - SwUserFieldType* pUField = const_cast<SwUserFieldType*>(static_cast<const SwUserFieldType*>(pFndExp->pFieldType)); + SwUserFieldType* pUField = const_cast<SwUserFieldType*>(static_cast<const SwUserFieldType*>(pFnd->pFieldType)); if( nsSwGetSetExpType::GSE_STRING & pUField->GetType() ) { - pFndExp->nValue.PutString( pUField->GetContent() ); + pFnd->nValue.PutString( pUField->GetContent() ); } else if( !pUField->IsValid() ) { @@ -477,7 +449,7 @@ SwCalcExp* SwCalc::VarLook( const OUString& rStr, bool bIns ) SwCalcOper eCurrOper = m_eCurrOper; SwCalcOper eCurrListOper = m_eCurrListOper; - pFndExp->nValue.PutDouble( pUField->GetValue( *this ) ); + pFnd->nValue.PutDouble( pUField->GetValue( *this ) ); // ...and write them back. m_nListPor = nListPor; @@ -489,18 +461,18 @@ SwCalcExp* SwCalc::VarLook( const OUString& rStr, bool bIns ) } else { - pFndExp->nValue.PutDouble( pUField->GetValue() ); + pFnd->nValue.PutDouble( pUField->GetValue() ); } } - else if ( !pFndExp->pFieldType && pFndExp->nValue.IsDBvalue() ) + else if ( !pFnd->pFieldType && pFnd->nValue.IsDBvalue() ) { - if ( pFndExp->nValue.IsString() ) - m_aErrExpr.nValue.PutString( pFndExp->nValue.GetOUString() ); - else if ( pFndExp->nValue.IsDouble() ) - m_aErrExpr.nValue.PutDouble( pFndExp->nValue.GetDouble() ); - pFndExp = &m_aErrExpr; + if ( pFnd->nValue.IsString() ) + m_aErrExpr.nValue.PutString( pFnd->nValue.GetOUString() ); + else if ( pFnd->nValue.IsDouble() ) + m_aErrExpr.nValue.PutDouble( pFnd->nValue.GetDouble() ); + pFnd = &m_aErrExpr; } - return pFndExp; + return pFnd; } // At this point the "real" case variable has to be used @@ -535,8 +507,8 @@ SwCalcExp* SwCalc::VarLook( const OUString& rStr, bool bIns ) } sal_uLong nTmpRec = 0; - if( nullptr != ( pFnd = Find( sDBNum, m_aVarTable, TBLSZ ) ) ) - nTmpRec = static_cast<SwCalcExp*>(pFnd)->nValue.GetULong(); + if( nullptr != ( pFnd = m_aVarTable.Find( sDBNum ) ) ) + nTmpRec = pFnd->nValue.GetULong(); OUString sResult; double nNumber = DBL_MAX; @@ -564,8 +536,8 @@ SwCalcExp* SwCalc::VarLook( const OUString& rStr, bool bIns ) } SwCalcExp* pNewExp = new SwCalcExp( aStr, SwSbxValue(), nullptr ); - pNewExp->pNext.reset( m_aVarTable[ ii ] ); - m_aVarTable[ ii ] = pNewExp; + pNewExp->pNext = std::move( m_aVarTable[ ii ] ); + m_aVarTable[ ii ].reset( pNewExp ); OUString sColumnName( GetColumnName( sTmpName )); OSL_ENSURE( !sColumnName.isEmpty(), "Missing DB column name" ); @@ -604,13 +576,13 @@ void SwCalc::VarChange( const OUString& rStr, const SwSbxValue& rValue ) OUString aStr = m_pCharClass->lowercase( rStr ); sal_uInt16 nPos = 0; - SwCalcExp* pFnd = static_cast<SwCalcExp*>(Find( aStr, m_aVarTable, TBLSZ, &nPos )); + SwCalcExp* pFnd = m_aVarTable.Find( aStr, &nPos ); if( !pFnd ) { pFnd = new SwCalcExp( aStr, SwSbxValue( rValue ), nullptr ); - pFnd->pNext.reset( m_aVarTable[ nPos ] ); - m_aVarTable[ nPos ] = pFnd; + pFnd->pNext = std::move( m_aVarTable[ nPos ] ); + m_aVarTable[ nPos ].reset( pFnd ); } else { @@ -1395,13 +1367,6 @@ SwHash::~SwHash() { } -void DeleteHashTable( SwHash **ppHashTable, sal_uInt16 nCount ) -{ - for ( sal_uInt16 i = 0; i < nCount; ++i ) - delete *(ppHashTable+i); - delete [] ppHashTable; -} - SwCalcExp::SwCalcExp(const OUString& rStr, const SwSbxValue& rVal, const SwFieldType* pType) : SwHash(rStr) diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx index 15b7c5a8313e..dd91855ff0c9 100644 --- a/sw/source/core/doc/DocumentFieldsManager.cxx +++ b/sw/source/core/doc/DocumentFieldsManager.cxx @@ -859,8 +859,7 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp const SwFieldTypes::size_type nHashSize {(( mpFieldTypes->size() / 7 ) + 1 ) * 7}; const sal_uInt16 nStrFormatCnt = static_cast<sal_uInt16>(nHashSize); OSL_ENSURE( nStrFormatCnt == nHashSize, "Downcasting to sal_uInt16 lost information!" ); - SwHash** pHashStrTable = new SwHash*[ nStrFormatCnt ]; - memset( pHashStrTable, 0, sizeof( HashStr* ) * nStrFormatCnt ); + SwHashTable<HashStr> aHashStrTable(nStrFormatCnt); { const SwFieldType* pFieldType; @@ -874,14 +873,14 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp sal_uInt16 nPos; const OUString& rNm = pFieldType->GetName(); OUString sExpand(const_cast<SwUserFieldType*>(static_cast<const SwUserFieldType*>(pFieldType))->Expand(nsSwGetSetExpType::GSE_STRING, 0, LANGUAGE_SYSTEM)); - SwHash* pFnd = Find( rNm, pHashStrTable, nStrFormatCnt, &nPos ); + SwHash* pFnd = aHashStrTable.Find( rNm, &nPos ); if( pFnd ) // modify entry in the hash table static_cast<HashStr*>(pFnd)->aSetStr = sExpand; else // insert the new entry - *(pHashStrTable + nPos ) = new HashStr( rNm, sExpand, - static_cast<HashStr*>(*(pHashStrTable + nPos)) ); + aHashStrTable[nPos].reset( new HashStr( rNm, sExpand, + aHashStrTable[nPos].release() ) ); } break; case SwFieldIds::SetExp: @@ -1019,18 +1018,18 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp // Add entry to hash table // Entry present? sal_uInt16 nPos; - SwHash* pFnd = Find( rName, pHashStrTable, nStrFormatCnt, &nPos ); + HashStr* pFnd = aHashStrTable.Find( rName, &nPos ); OUString const value(pField->ExpandField(m_rDoc.IsClipBoard())); if( pFnd ) { // Modify entry in the hash table - static_cast<HashStr*>(pFnd)->aSetStr = value; + pFnd->aSetStr = value; } else { // insert new entry - *(pHashStrTable + nPos ) = new HashStr( rName, - value, static_cast<HashStr *>(*(pHashStrTable + nPos))); + aHashStrTable[nPos].reset( new HashStr( rName, + value, aHashStrTable[nPos].release()) ); } #endif } @@ -1047,8 +1046,7 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp if( (!pUpdateField || pUpdateField == pTextField ) && pGField->IsInBodyText() ) { - aNew = LookString( pHashStrTable, nStrFormatCnt, - pGField->GetFormula() ); + aNew = LookString( aHashStrTable, pGField->GetFormula() ); pGField->ChgExpStr( aNew ); } } @@ -1056,8 +1054,7 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp { SwSetExpField* pSField = const_cast<SwSetExpField*>(static_cast<const SwSetExpField*>(pField)); // is the "formula" a field? - aNew = LookString( pHashStrTable, nStrFormatCnt, - pSField->GetFormula() ); + aNew = LookString( aHashStrTable, pSField->GetFormula() ); if( aNew.isEmpty() ) // nothing found then the formula is the new value aNew = pSField->GetFormula(); @@ -1070,19 +1067,20 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp aNew = static_cast<SwSetExpFieldType*>(pSField->GetTyp())->GetSetRefName(); // Entry present? sal_uInt16 nPos; - SwHash* pFnd = Find( aNew, pHashStrTable, nStrFormatCnt, &nPos ); + HashStr* pFnd = aHashStrTable.Find( aNew, &nPos ); if( pFnd ) // Modify entry in the hash table - static_cast<HashStr*>(pFnd)->aSetStr = pSField->GetExpStr(); + pFnd->aSetStr = pSField->GetExpStr(); else // insert new entry - *(pHashStrTable + nPos ) = pFnd = new HashStr( aNew, + aHashStrTable[nPos].reset( new HashStr( aNew, pSField->GetExpStr(), - static_cast<HashStr*>(*(pHashStrTable + nPos) )); + aHashStrTable[nPos].release() ) ); + pFnd = aHashStrTable[nPos].get(); // Extension for calculation with Strings SwSbxValue aValue; - aValue.PutString( static_cast<HashStr*>(pFnd)->aSetStr ); + aValue.PutString( pFnd->aSetStr ); aCalc.VarChange( aNew, aValue ); } } @@ -1162,8 +1160,6 @@ void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUp #if HAVE_FEATURE_DBCONNECTIVITY pMgr->CloseAll(false); #endif - // delete hash table - ::DeleteHashTable( pHashStrTable, nStrFormatCnt ); // update reference fields if( bUpdRefFields ) @@ -1472,7 +1468,7 @@ void DocumentFieldsManager::FieldsToCalc( SwCalc& rCalc, sal_uLong nLastNd, sal_ #endif } -void DocumentFieldsManager::FieldsToExpand( SwHash**& ppHashTable, sal_uInt16& rTableSize, +void DocumentFieldsManager::FieldsToExpand( SwHashTable<HashStr> & rHashTable, const SetGetExpField& rToThisField ) { // create the sorted list of all SetFields @@ -1481,9 +1477,8 @@ void DocumentFieldsManager::FieldsToExpand( SwHash**& ppHashTable, sal_uInt16& r // Hash table for all string replacements is filled on-the-fly. // Try to fabricate an uneven number. - rTableSize = (( mpUpdateFields->GetSortLst()->size() / 7 ) + 1 ) * 7; - ppHashTable = new SwHash*[ rTableSize ]; - memset( ppHashTable, 0, sizeof( HashStr* ) * rTableSize ); + sal_uInt16 nTableSize = (( mpUpdateFields->GetSortLst()->size() / 7 ) + 1 ) * 7; + rHashTable.resize(nTableSize); SetGetExpFields::const_iterator const itLast = mpUpdateFields->GetSortLst()->upper_bound( @@ -1504,7 +1499,7 @@ void DocumentFieldsManager::FieldsToExpand( SwHash**& ppHashTable, sal_uInt16& r // set the new value in the hash table // is the formula a field? SwSetExpField* pSField = const_cast<SwSetExpField*>(static_cast<const SwSetExpField*>(pField)); - OUString aNew = LookString( ppHashTable, rTableSize, pSField->GetFormula() ); + OUString aNew = LookString( rHashTable, pSField->GetFormula() ); if( aNew.isEmpty() ) // nothing found, then the formula is aNew = pSField->GetFormula(); // the new value @@ -1517,14 +1512,14 @@ void DocumentFieldsManager::FieldsToExpand( SwHash**& ppHashTable, sal_uInt16& r aNew = static_cast<SwSetExpFieldType*>(pSField->GetTyp())->GetSetRefName(); // Entry present? sal_uInt16 nPos; - SwHash* pFnd = Find( aNew, ppHashTable, rTableSize, &nPos ); + SwHash* pFnd = rHashTable.Find( aNew, &nPos ); if( pFnd ) // modify entry in the hash table static_cast<HashStr*>(pFnd)->aSetStr = pSField->GetExpStr(); else // insert the new entry - *(ppHashTable + nPos ) = new HashStr( aNew, - pSField->GetExpStr(), static_cast<HashStr*>(*(ppHashTable + nPos)) ); + rHashTable[nPos].reset( new HashStr( aNew, + pSField->GetExpStr(), rHashTable[nPos].release() ) ); } break; case SwFieldIds::Database: @@ -1534,18 +1529,18 @@ void DocumentFieldsManager::FieldsToExpand( SwHash**& ppHashTable, sal_uInt16& r // Insert entry in the hash table // Entry present? sal_uInt16 nPos; - SwHash* pFnd = Find( rName, ppHashTable, rTableSize, &nPos ); + HashStr* pFnd = rHashTable.Find( rName, &nPos ); OUString const value(pField->ExpandField(m_rDoc.IsClipBoard())); if( pFnd ) { // modify entry in the hash table - static_cast<HashStr*>(pFnd)->aSetStr = value; + pFnd->aSetStr = value; } else { // insert the new entry - *(ppHashTable + nPos ) = new HashStr( rName, - value, static_cast<HashStr *>(*(ppHashTable + nPos))); + rHashTable[nPos].reset( new HashStr( rName, + value, rHashTable[nPos].release()) ); } } break; diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx index 32d1d9f936da..71e5ac994eac 100644 --- a/sw/source/core/doc/docfld.cxx +++ b/sw/source/core/doc/docfld.cxx @@ -331,11 +331,11 @@ HashStr::HashStr( const OUString& rName, const OUString& rText, } /// Look up the Name, if it is present, return its String, otherwise return an empty String -OUString LookString( SwHash** ppTable, sal_uInt16 nSize, const OUString& rName ) +OUString LookString( SwHashTable<HashStr> const & rTable, const OUString& rName ) { - SwHash* pFnd = Find( comphelper::string::strip(rName, ' '), ppTable, nSize ); + HashStr* pFnd = rTable.Find( comphelper::string::strip(rName, ' ') ); if( pFnd ) - return static_cast<HashStr*>(pFnd)->aSetStr; + return pFnd->aSetStr; return OUString(); } @@ -1098,7 +1098,7 @@ void SwDocUpdateField::InsertFieldType( const SwFieldType& rType ) sFieldName = GetAppCharClass().lowercase( sFieldName ); sal_uInt16 n; - SwHash* pFnd = Find( sFieldName, GetFieldTypeTable(), TBLSZ, &n ); + SwCalcFieldType* pFnd = GetFieldTypeTable().Find( sFieldName, &n ); if( !pFnd ) { @@ -1130,7 +1130,7 @@ void SwDocUpdateField::RemoveFieldType( const SwFieldType& rType ) sFieldName = GetAppCharClass().lowercase( sFieldName ); sal_uInt16 n; - SwHash* pFnd = Find( sFieldName, GetFieldTypeTable(), TBLSZ, &n ); + SwCalcFieldType* pFnd = GetFieldTypeTable().Find( sFieldName, &n ); if( pFnd ) { if( aFieldTypeTable[ n ].get() == pFnd ) @@ -1150,7 +1150,8 @@ void SwDocUpdateField::RemoveFieldType( const SwFieldType& rType ) } SwDocUpdateField::SwDocUpdateField(SwDoc* pDoc) - : nNodes(0) + : aFieldTypeTable(TBLSZ) + , nNodes(0) , nFieldLstGetMode(0) , pDocument(pDoc) , bInUpdateFields(false) diff --git a/sw/source/core/edit/editsh.cxx b/sw/source/core/edit/editsh.cxx index a3f53c734522..9ac89cd6f01b 100644 --- a/sw/source/core/edit/editsh.cxx +++ b/sw/source/core/edit/editsh.cxx @@ -544,7 +544,7 @@ OUString SwEditShell::Calculate() OUString sVar = aStr.copy( nTmpStt, nPos - nTmpStt ); if( !::FindOperator( sVar ) && - (::Find( sVar, aCalc.GetVarTable(),TBLSZ) || + (aCalc.GetVarTable().Find(sVar) || aCalc.VarLook( sVar )) ) { if( !bValidFields ) diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx index 77e8d9b3b54c..b01aa8fd31e5 100644 --- a/sw/source/core/fields/expfld.cxx +++ b/sw/source/core/fields/expfld.cxx @@ -357,11 +357,9 @@ void SwGetExpField::ChangeExpansion( const SwFrame& rFrame, const SwTextField& r SetGetExpField aEndField( aPos.nNode, &rField, &aPos.nContent ); if(GetSubType() & nsSwGetSetExpType::GSE_STRING) { - SwHash** ppHashTable; - sal_uInt16 nSize; - rDoc.getIDocumentFieldsAccess().FieldsToExpand( ppHashTable, nSize, aEndField ); - sExpand = LookString( ppHashTable, nSize, GetFormula() ); - ::DeleteHashTable( ppHashTable, nSize ); + SwHashTable<HashStr> aHashTable(0); + rDoc.getIDocumentFieldsAccess().FieldsToExpand( aHashTable, aEndField ); + sExpand = LookString( aHashTable, GetFormula() ); } else { diff --git a/sw/source/core/inc/DocumentFieldsManager.hxx b/sw/source/core/inc/DocumentFieldsManager.hxx index c0dbb6303e60..d87f848d34b5 100644 --- a/sw/source/core/inc/DocumentFieldsManager.hxx +++ b/sw/source/core/inc/DocumentFieldsManager.hxx @@ -56,7 +56,7 @@ public: virtual void SetFixFields(const DateTime* pNewDateTime) override; virtual void FieldsToCalc(SwCalc& rCalc, sal_uLong nLastNd, sal_uInt16 nLastCnt) override; virtual void FieldsToCalc(SwCalc& rCalc, const SetGetExpField& rToThisField) override; - virtual void FieldsToExpand(SwHash**& ppTable, sal_uInt16& rTableSize, const SetGetExpField& rToThisField) override; + virtual void FieldsToExpand(SwHashTable<HashStr>& rTable, const SetGetExpField& rToThisField) override; virtual bool IsNewFieldLst() const override; virtual void SetNewFieldLst( bool bFlag) override; virtual void InsDelFieldInFieldLst(bool bIns, const SwTextField& rField) override; diff --git a/sw/source/core/inc/docfld.hxx b/sw/source/core/inc/docfld.hxx index 13402935dde4..ab0b6a1f9492 100644 --- a/sw/source/core/inc/docfld.hxx +++ b/sw/source/core/inc/docfld.hxx @@ -125,7 +125,7 @@ struct SwCalcFieldType : public SwHash }; // search for the string that was saved under rName in the hash table -OUString LookString( SwHash** ppTable, sal_uInt16 nSize, const OUString& rName ); +OUString LookString( SwHashTable<HashStr> const & rTable, const OUString& rName ); const int GETFLD_ALL = 3; // combine flags via OR const int GETFLD_CALC = 1; @@ -134,7 +134,7 @@ const int GETFLD_EXPAND = 2; class SwDocUpdateField { std::unique_ptr<SetGetExpFields> pFieldSortLst; // current field list for calculation - std::unique_ptr<SwCalcFieldType> aFieldTypeTable[ TBLSZ ]; + SwHashTable<SwCalcFieldType> aFieldTypeTable; sal_uLong nNodes; // if the node count is different sal_uInt8 nFieldLstGetMode; @@ -174,7 +174,7 @@ public: } } - SwHash* const * GetFieldTypeTable() const { return reinterpret_cast<SwHash* const *>(aFieldTypeTable); } + SwHashTable<SwCalcFieldType> const & GetFieldTypeTable() const { return aFieldTypeTable; } }; #endif |