[Libreoffice-commits] core.git: 2 commits - framework/source sw/inc sw/source
Noel Grandin
noel.grandin at collabora.co.uk
Tue Mar 20 06:45:47 UTC 2018
framework/source/uiconfiguration/ImageList.cxx | 6 -
framework/source/uiconfiguration/ImplImageList.cxx | 8 -
framework/source/uiconfiguration/image.h | 2
sw/inc/IDocumentFieldsAccess.hxx | 4
sw/inc/calc.hxx | 42 +++++++-
sw/source/core/bastyp/calc.cxx | 109 +++++++--------------
sw/source/core/doc/DocumentFieldsManager.cxx | 59 +++++------
sw/source/core/doc/docfld.cxx | 13 +-
sw/source/core/edit/editsh.cxx | 2
sw/source/core/fields/expfld.cxx | 8 -
sw/source/core/inc/DocumentFieldsManager.hxx | 2
sw/source/core/inc/docfld.hxx | 6 -
12 files changed, 126 insertions(+), 135 deletions(-)
New commits:
commit 70d2fd4823353550a0e7ffd61585ec1a8a51e907
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Mon Mar 19 14:18:37 2018 +0200
loplugin:useuniqueptr in ImplImageList
and fix leak in RemoveImage in the process
Change-Id: I20e395178f92f7127e99011aebbe97246f255d1d
Reviewed-on: https://gerrit.libreoffice.org/51550
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/framework/source/uiconfiguration/ImageList.cxx b/framework/source/uiconfiguration/ImageList.cxx
index 575cfd8de6c6..870d8e3e10db 100644
--- a/framework/source/uiconfiguration/ImageList.cxx
+++ b/framework/source/uiconfiguration/ImageList.cxx
@@ -68,7 +68,7 @@ BitmapEx ImageList::GetAsHorizontalStrip() const
// Load any stragglers
for (sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++)
{
- ImageAryData *pData = mpImplData->maImages[ nIdx ];
+ ImageAryData *pData = mpImplData->maImages[ nIdx ].get();
if( pData->IsLoadable() )
pData->Load( mpImplData->maPrefix );
}
@@ -81,7 +81,7 @@ BitmapEx ImageList::GetAsHorizontalStrip() const
{
tools::Rectangle aDestRect( Point( nIdx * mpImplData->maImageSize.Width(), 0 ),
mpImplData->maImageSize );
- ImageAryData *pData = mpImplData->maImages[ nIdx ];
+ ImageAryData *pData = mpImplData->maImages[ nIdx ].get();
aResult.CopyPixel( aDestRect, aSrcRect, &pData->maBitmapEx);
}
@@ -214,7 +214,7 @@ void ImageList::GetImageNames( std::vector< OUString >& rNames ) const
if( mpImplData )
{
- for(const ImageAryData* pImage : mpImplData->maImages)
+ for(auto const & pImage : mpImplData->maImages)
{
const OUString& rName( pImage->maName );
if( !rName.isEmpty())
diff --git a/framework/source/uiconfiguration/ImplImageList.cxx b/framework/source/uiconfiguration/ImplImageList.cxx
index c759acd6fdf4..1c594f16bf89 100644
--- a/framework/source/uiconfiguration/ImplImageList.cxx
+++ b/framework/source/uiconfiguration/ImplImageList.cxx
@@ -41,7 +41,7 @@ ImplImageList::ImplImageList( const ImplImageList &aSrc )
for (auto const& elem : aSrc.maImages)
{
ImageAryData* pAryData = new ImageAryData(*elem);
- maImages.push_back( pAryData );
+ maImages.emplace_back( pAryData );
if( !pAryData->maName.isEmpty() )
maNameHash [ pAryData->maName ] = pAryData;
}
@@ -49,22 +49,20 @@ ImplImageList::ImplImageList( const ImplImageList &aSrc )
ImplImageList::~ImplImageList()
{
- for (auto const& elem : maImages)
- delete elem;
}
void ImplImageList::AddImage( const OUString &aName,
sal_uInt16 nId, const BitmapEx &aBitmapEx )
{
ImageAryData *pImg = new ImageAryData( aName, nId, aBitmapEx );
- maImages.push_back( pImg );
+ maImages.emplace_back( pImg );
if( !aName.isEmpty() )
maNameHash [ aName ] = pImg;
}
void ImplImageList::RemoveImage( sal_uInt16 nPos )
{
- ImageAryData *pImg = maImages[ nPos ];
+ ImageAryData *pImg = maImages[ nPos ].get();
if( !pImg->maName.isEmpty() )
maNameHash.erase( pImg->maName );
maImages.erase( maImages.begin() + nPos );
diff --git a/framework/source/uiconfiguration/image.h b/framework/source/uiconfiguration/image.h
index 1005fc39cdf1..96c952d3dfe3 100644
--- a/framework/source/uiconfiguration/image.h
+++ b/framework/source/uiconfiguration/image.h
@@ -48,7 +48,7 @@ struct ImplImageList
typedef std::unordered_map< OUString, ImageAryData * >
ImageAryDataNameHash;
- std::vector<ImageAryData *> maImages;
+ std::vector< std::unique_ptr<ImageAryData> > maImages;
ImageAryDataNameHash maNameHash;
OUString maPrefix;
Size maImageSize;
commit 58e798c366ba2381a0bf6422036bebe9763035a6
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Mon Mar 19 14:42:42 2018 +0200
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 at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sw/inc/IDocumentFieldsAccess.hxx b/sw/inc/IDocumentFieldsAccess.hxx
index 78d0e190b4a2..e5f49aac1186 100644
--- a/sw/inc/IDocumentFieldsAccess.hxx
+++ b/sw/inc/IDocumentFieldsAccess.hxx
@@ -37,6 +37,8 @@ class SetGetExpField;
struct SwHash;
class SwNode;
enum class SwFieldIds : sal_uInt16;
+template <class T> class SwHashTable;
+struct HashStr;
namespace rtl { class OUString; }
using rtl::OUString;
@@ -123,7 +125,7 @@ namespace com { namespace sun { namespace star { namespace uno { class Any; } }
virtual void FieldsToCalc(SwCalc& rCalc, const SetGetExpField& rToThisField) = 0;
- virtual void FieldsToExpand(SwHash**& ppTable, sal_uInt16& rTableSize, const SetGetExpField& rToThisField) = 0;
+ virtual void FieldsToExpand(SwHashTable<HashStr> & rTable, const SetGetExpField& rToThisField) = 0;
virtual bool IsNewFieldLst() const = 0;
diff --git a/sw/inc/calc.hxx b/sw/inc/calc.hxx
index a5bd797a24a1..75112605f492 100644
--- a/sw/inc/calc.hxx
+++ b/sw/inc/calc.hxx
@@ -136,10 +136,42 @@ struct SwCalcExp : public SwHash
const SwFieldType* pFieldType );
};
-SwHash* Find( const OUString& rSrch, SwHash* const * ppTable,
- sal_uInt16 nTableSize, sal_uInt16* pPos = nullptr );
+/// T should be a subclass of SwHash
+template<class T>
+class SwHashTable
+{
+ std::vector<std::unique_ptr<T>> aData;
+public:
+ SwHashTable(size_t nSize) : aData(nSize) {}
+ std::unique_ptr<T> & operator[](size_t idx) { return aData[idx]; }
+ std::unique_ptr<T> const & operator[](size_t idx) const { return aData[idx]; }
+ void resize(size_t nSize) { aData.resize(nSize); }
+
+ T* Find( const OUString& rStr, sal_uInt16* pPos = nullptr ) const
+ {
+ size_t nTableSize = aData.size();
+ 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( T* pEntry = aData[ii].get(); pEntry; pEntry = static_cast<T*>(pEntry->pNext.get()) )
+ {
+ if( rStr == pEntry->aStr )
+ {
+ return pEntry;
+ }
+ }
+ return nullptr;
+ }
+
+};
-void DeleteHashTable( SwHash** ppTable, sal_uInt16 nTableSize );
// if CalcOp != 0, this is a valid operator
struct CalcOp;
@@ -149,7 +181,7 @@ extern "C" typedef double (*pfCalc)(double);
class SwCalc
{
- SwHash* m_aVarTable[ TBLSZ ];
+ SwHashTable<SwCalcExp> m_aVarTable;
OUString m_aVarName, m_sCurrSym;
OUString m_sCommand;
std::vector<const SwUserFieldType*> m_aRekurStack;
@@ -193,7 +225,7 @@ public:
SwCalcExp* VarLook( const OUString &rStr, bool bIns = false );
void VarChange( const OUString& rStr, const SwSbxValue& rValue );
void VarChange( const OUString& rStr, double );
- SwHash** GetVarTable() { return m_aVarTable; }
+ SwHashTable<SwCalcExp> & GetVarTable() { return m_aVarTable; }
bool Push(const SwUserFieldType* pUserFieldType);
void Pop();
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
More information about the Libreoffice-commits
mailing list