Kaydet (Commit) a5c23283 authored tarafından Arnaud Versini's avatar Arnaud Versini Kaydeden (comit) Noel Grandin

BASIC: Store directly SbxVarEntry in SbxArray

Change-Id: I64ae6c2a45e0ed880f5b76ca2ad420d684fdfeb4
Reviewed-on: https://gerrit.libreoffice.org/21308Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
Tested-by: 's avatarArnaud Versini <arnaud.versini@libreoffice.org>
üst b4b0cc2a
...@@ -62,14 +62,9 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray ) ...@@ -62,14 +62,9 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray )
Clear(); Clear();
for( const auto& rpSrcRef : *rArray.mpVarEntries ) for( const auto& rpSrcRef : *rArray.mpVarEntries )
{ {
SbxVariableRef pSrc_ = rpSrcRef->mpVar; SbxVariableRef pSrc_ = rpSrcRef.mpVar;
if( !pSrc_ ) if( !pSrc_ )
continue; continue;
SbxVarEntry* pDstRef = new SbxVarEntry;
pDstRef->mpVar = rpSrcRef->mpVar;
if (rpSrcRef->maAlias)
pDstRef->maAlias.reset(*rpSrcRef->maAlias);
if( eType != SbxVARIANT ) if( eType != SbxVARIANT )
{ {
...@@ -79,7 +74,7 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray ) ...@@ -79,7 +74,7 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray )
pSrc_->Convert(eType); pSrc_->Convert(eType);
} }
} }
mpVarEntries->push_back( pDstRef ); mpVarEntries->push_back( rpSrcRef );
} }
} }
return *this; return *this;
...@@ -87,7 +82,6 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray ) ...@@ -87,7 +82,6 @@ SbxArray& SbxArray::operator=( const SbxArray& rArray )
SbxArray::~SbxArray() SbxArray::~SbxArray()
{ {
Clear();
delete mpVarEntries; delete mpVarEntries;
} }
...@@ -103,12 +97,6 @@ SbxClassType SbxArray::GetClass() const ...@@ -103,12 +97,6 @@ SbxClassType SbxArray::GetClass() const
void SbxArray::Clear() void SbxArray::Clear()
{ {
sal_uInt32 nSize = mpVarEntries->size();
for( sal_uInt32 i = 0 ; i < nSize ; i++ )
{
SbxVarEntry* pEntry = (*mpVarEntries)[i];
delete pEntry;
}
mpVarEntries->clear(); mpVarEntries->clear();
} }
...@@ -136,9 +124,9 @@ SbxVariableRef& SbxArray::GetRef32( sal_uInt32 nIdx ) ...@@ -136,9 +124,9 @@ SbxVariableRef& SbxArray::GetRef32( sal_uInt32 nIdx )
} }
while( mpVarEntries->size() <= nIdx ) while( mpVarEntries->size() <= nIdx )
{ {
mpVarEntries->push_back(new SbxVarEntry); mpVarEntries->push_back(SbxVarEntry());
} }
return (*mpVarEntries)[nIdx]->mpVar; return (*mpVarEntries)[nIdx].mpVar;
} }
SbxVariableRef& SbxArray::GetRef( sal_uInt16 nIdx ) SbxVariableRef& SbxArray::GetRef( sal_uInt16 nIdx )
...@@ -153,9 +141,9 @@ SbxVariableRef& SbxArray::GetRef( sal_uInt16 nIdx ) ...@@ -153,9 +141,9 @@ SbxVariableRef& SbxArray::GetRef( sal_uInt16 nIdx )
} }
while( mpVarEntries->size() <= nIdx ) while( mpVarEntries->size() <= nIdx )
{ {
mpVarEntries->push_back(new SbxVarEntry); mpVarEntries->push_back(SbxVarEntry());
} }
return (*mpVarEntries)[nIdx]->mpVar; return (*mpVarEntries)[nIdx].mpVar;
} }
SbxVariable* SbxArray::Get32( sal_uInt32 nIdx ) SbxVariable* SbxArray::Get32( sal_uInt32 nIdx )
...@@ -263,8 +251,8 @@ void SbxArray::Insert32( SbxVariable* pVar, sal_uInt32 nIdx ) ...@@ -263,8 +251,8 @@ void SbxArray::Insert32( SbxVariable* pVar, sal_uInt32 nIdx )
{ {
return; return;
} }
SbxVarEntry* p = new SbxVarEntry; SbxVarEntry p;
p->mpVar = pVar; p.mpVar = pVar;
size_t nSize = mpVarEntries->size(); size_t nSize = mpVarEntries->size();
if( nIdx > nSize ) if( nIdx > nSize )
{ {
...@@ -272,7 +260,7 @@ void SbxArray::Insert32( SbxVariable* pVar, sal_uInt32 nIdx ) ...@@ -272,7 +260,7 @@ void SbxArray::Insert32( SbxVariable* pVar, sal_uInt32 nIdx )
} }
if( eType != SbxVARIANT && pVar ) if( eType != SbxVARIANT && pVar )
{ {
p->mpVar->Convert(eType); p.mpVar->Convert(eType);
} }
if( nIdx == nSize ) if( nIdx == nSize )
{ {
...@@ -299,9 +287,7 @@ void SbxArray::Remove32( sal_uInt32 nIdx ) ...@@ -299,9 +287,7 @@ void SbxArray::Remove32( sal_uInt32 nIdx )
{ {
if( nIdx < mpVarEntries->size() ) if( nIdx < mpVarEntries->size() )
{ {
SbxVarEntry* pRef = (*mpVarEntries)[nIdx];
mpVarEntries->erase( mpVarEntries->begin() + nIdx ); mpVarEntries->erase( mpVarEntries->begin() + nIdx );
delete pRef;
SetFlag( SbxFlagBits::Modified ); SetFlag( SbxFlagBits::Modified );
} }
} }
...@@ -310,9 +296,7 @@ void SbxArray::Remove( sal_uInt16 nIdx ) ...@@ -310,9 +296,7 @@ void SbxArray::Remove( sal_uInt16 nIdx )
{ {
if( nIdx < mpVarEntries->size() ) if( nIdx < mpVarEntries->size() )
{ {
SbxVarEntry* pRef = (*mpVarEntries)[nIdx];
mpVarEntries->erase( mpVarEntries->begin() + nIdx ); mpVarEntries->erase( mpVarEntries->begin() + nIdx );
delete pRef;
SetFlag( SbxFlagBits::Modified ); SetFlag( SbxFlagBits::Modified );
} }
} }
...@@ -323,8 +307,7 @@ void SbxArray::Remove( SbxVariable* pVar ) ...@@ -323,8 +307,7 @@ void SbxArray::Remove( SbxVariable* pVar )
{ {
for( size_t i = 0; i < mpVarEntries->size(); i++ ) for( size_t i = 0; i < mpVarEntries->size(); i++ )
{ {
SbxVarEntry* pRef = (*mpVarEntries)[i]; if (&(*mpVarEntries)[i].mpVar == pVar)
if (&pRef->mpVar == pVar)
{ {
Remove32( i ); break; Remove32( i ); break;
} }
...@@ -340,41 +323,39 @@ void SbxArray::Merge( SbxArray* p ) ...@@ -340,41 +323,39 @@ void SbxArray::Merge( SbxArray* p )
if (!p) if (!p)
return; return;
for (sal_uInt16 i = 0; i < p->Count(); ++i) for (auto& rEntry1: *p->mpVarEntries)
{ {
SbxVarEntry* pEntry1 = (*p->mpVarEntries)[i]; if (!rEntry1.mpVar)
if (!pEntry1->mpVar)
continue; continue;
OUString aName = pEntry1->mpVar->GetName(); OUString aName = rEntry1.mpVar->GetName();
sal_uInt16 nHash = pEntry1->mpVar->GetHashCode(); sal_uInt16 nHash = rEntry1.mpVar->GetHashCode();
// Is the element by the same name already inside? // Is the element by the same name already inside?
// Then overwrite! // Then overwrite!
for (size_t j = 0; j < mpVarEntries->size(); ++j) for (auto& rEntry2: *mpVarEntries)
{ {
SbxVarEntry* pEntry2 = (*mpVarEntries)[j]; if (!rEntry2.mpVar)
if (!pEntry2->mpVar)
continue; continue;
if (pEntry2->mpVar->GetHashCode() == nHash && if (rEntry2.mpVar->GetHashCode() == nHash &&
pEntry2->mpVar->GetName().equalsIgnoreAsciiCase(aName)) rEntry2.mpVar->GetName().equalsIgnoreAsciiCase(aName))
{ {
// Take this element and clear the original. // Take this element and clear the original.
pEntry2->mpVar = pEntry1->mpVar; rEntry2.mpVar = rEntry1.mpVar;
pEntry1->mpVar.Clear(); rEntry2.mpVar.Clear();
break; break;
} }
} }
if (pEntry1->mpVar) if (rEntry1.mpVar)
{ {
// We don't have element with the same name. Add a new entry. // We don't have element with the same name. Add a new entry.
SbxVarEntry* pNewEntry = new SbxVarEntry; SbxVarEntry aNewEntry;
mpVarEntries->push_back(pNewEntry); aNewEntry.mpVar = rEntry1.mpVar;
pNewEntry->mpVar = pEntry1->mpVar; if (rEntry1.maAlias)
if (pEntry1->maAlias) aNewEntry.maAlias.reset(*rEntry1.maAlias);
pNewEntry->maAlias.reset(*pEntry1->maAlias); mpVarEntries->push_back(aNewEntry);
} }
} }
} }
...@@ -385,36 +366,35 @@ void SbxArray::Merge( SbxArray* p ) ...@@ -385,36 +366,35 @@ void SbxArray::Merge( SbxArray* p )
SbxVariable* SbxArray::FindUserData( sal_uInt32 nData ) SbxVariable* SbxArray::FindUserData( sal_uInt32 nData )
{ {
SbxVariable* p = nullptr; SbxVariable* p = nullptr;
for (size_t i = 0; i < mpVarEntries->size(); ++i) for (auto& rEntry : *mpVarEntries)
{ {
SbxVarEntry* pEntry = (*mpVarEntries)[i]; if (!rEntry.mpVar)
if (!pEntry->mpVar)
continue; continue;
if (pEntry->mpVar->IsVisible() && pEntry->mpVar->GetUserData() == nData) if (rEntry.mpVar->IsVisible() && rEntry.mpVar->GetUserData() == nData)
{ {
p = &pEntry->mpVar; p = &rEntry.mpVar;
p->ResetFlag( SbxFlagBits::ExtFound ); p->ResetFlag( SbxFlagBits::ExtFound );
break; // JSM 1995-10-06 break; // JSM 1995-10-06
} }
// Did we have an array/object with extended search? // Did we have an array/object with extended search?
if (pEntry->mpVar->IsSet(SbxFlagBits::ExtSearch)) if (rEntry.mpVar->IsSet(SbxFlagBits::ExtSearch))
{ {
switch (pEntry->mpVar->GetClass()) switch (rEntry.mpVar->GetClass())
{ {
case SbxCLASS_OBJECT: case SbxCLASS_OBJECT:
{ {
// Objects are not allowed to scan their parent. // Objects are not allowed to scan their parent.
SbxFlagBits nOld = pEntry->mpVar->GetFlags(); SbxFlagBits nOld = rEntry.mpVar->GetFlags();
pEntry->mpVar->ResetFlag(SbxFlagBits::GlobalSearch); rEntry.mpVar->ResetFlag(SbxFlagBits::GlobalSearch);
p = static_cast<SbxObject&>(*pEntry->mpVar).FindUserData(nData); p = static_cast<SbxObject&>(*rEntry.mpVar).FindUserData(nData);
pEntry->mpVar->SetFlags(nOld); rEntry.mpVar->SetFlags(nOld);
} }
break; break;
case SbxCLASS_ARRAY: case SbxCLASS_ARRAY:
// Casting SbxVariable to SbxArray? Really? // Casting SbxVariable to SbxArray? Really?
p = reinterpret_cast<SbxArray&>(*pEntry->mpVar).FindUserData(nData); p = reinterpret_cast<SbxArray&>(*rEntry.mpVar).FindUserData(nData);
break; break;
default: default:
; ;
...@@ -436,45 +416,43 @@ SbxVariable* SbxArray::FindUserData( sal_uInt32 nData ) ...@@ -436,45 +416,43 @@ SbxVariable* SbxArray::FindUserData( sal_uInt32 nData )
SbxVariable* SbxArray::Find( const OUString& rName, SbxClassType t ) SbxVariable* SbxArray::Find( const OUString& rName, SbxClassType t )
{ {
SbxVariable* p = nullptr; SbxVariable* p = nullptr;
sal_uInt32 nCount = mpVarEntries->size(); if( mpVarEntries->empty() )
if( !nCount )
return nullptr; return nullptr;
bool bExtSearch = IsSet( SbxFlagBits::ExtSearch ); bool bExtSearch = IsSet( SbxFlagBits::ExtSearch );
sal_uInt16 nHash = SbxVariable::MakeHashCode( rName ); sal_uInt16 nHash = SbxVariable::MakeHashCode( rName );
for( sal_uInt32 i = 0; i < nCount; i++ ) for (auto& rEntry : *mpVarEntries)
{ {
SbxVarEntry* pEntry = (*mpVarEntries)[i]; if (!rEntry.mpVar || !rEntry.mpVar->IsVisible())
if (!pEntry->mpVar || !pEntry->mpVar->IsVisible())
continue; continue;
// The very secure search works as well, if there is no hashcode! // The very secure search works as well, if there is no hashcode!
sal_uInt16 nVarHash = pEntry->mpVar->GetHashCode(); sal_uInt16 nVarHash = rEntry.mpVar->GetHashCode();
if ( (!nVarHash || nVarHash == nHash) if ( (!nVarHash || nVarHash == nHash)
&& (t == SbxCLASS_DONTCARE || pEntry->mpVar->GetClass() == t) && (t == SbxCLASS_DONTCARE || rEntry.mpVar->GetClass() == t)
&& (pEntry->mpVar->GetName().equalsIgnoreAsciiCase(rName))) && (rEntry.mpVar->GetName().equalsIgnoreAsciiCase(rName)))
{ {
p = &pEntry->mpVar; p = &rEntry.mpVar;
p->ResetFlag(SbxFlagBits::ExtFound); p->ResetFlag(SbxFlagBits::ExtFound);
break; break;
} }
// Did we have an array/object with extended search? // Did we have an array/object with extended search?
if (bExtSearch && pEntry->mpVar->IsSet(SbxFlagBits::ExtSearch)) if (bExtSearch && rEntry.mpVar->IsSet(SbxFlagBits::ExtSearch))
{ {
switch (pEntry->mpVar->GetClass()) switch (rEntry.mpVar->GetClass())
{ {
case SbxCLASS_OBJECT: case SbxCLASS_OBJECT:
{ {
// Objects are not allowed to scan their parent. // Objects are not allowed to scan their parent.
SbxFlagBits nOld = pEntry->mpVar->GetFlags(); SbxFlagBits nOld = rEntry.mpVar->GetFlags();
pEntry->mpVar->ResetFlag(SbxFlagBits::GlobalSearch); rEntry.mpVar->ResetFlag(SbxFlagBits::GlobalSearch);
p = static_cast<SbxObject&>(*pEntry->mpVar).Find(rName, t); p = static_cast<SbxObject&>(*rEntry.mpVar).Find(rName, t);
pEntry->mpVar->SetFlags(nOld); rEntry.mpVar->SetFlags(nOld);
} }
break; break;
case SbxCLASS_ARRAY: case SbxCLASS_ARRAY:
// Casting SbxVariable to SbxArray? Really? // Casting SbxVariable to SbxArray? Really?
p = reinterpret_cast<SbxArray&>(*pEntry->mpVar).Find(rName, t); p = reinterpret_cast<SbxArray&>(*rEntry.mpVar).Find(rName, t);
break; break;
default: default:
; ;
...@@ -522,22 +500,20 @@ bool SbxArray::LoadData( SvStream& rStrm, sal_uInt16 /*nVer*/ ) ...@@ -522,22 +500,20 @@ bool SbxArray::LoadData( SvStream& rStrm, sal_uInt16 /*nVer*/ )
bool SbxArray::StoreData( SvStream& rStrm ) const bool SbxArray::StoreData( SvStream& rStrm ) const
{ {
sal_uInt32 nElem = 0; sal_uInt32 nElem = 0;
sal_uInt32 n;
// Which elements are even defined? // Which elements are even defined?
for( n = 0; n < mpVarEntries->size(); n++ ) for( auto& rEntry: *mpVarEntries )
{ {
SbxVarEntry* pEntry = (*mpVarEntries)[n]; if (rEntry.mpVar && !(rEntry.mpVar->GetFlags() & SbxFlagBits::DontStore))
if (pEntry->mpVar && !(pEntry->mpVar->GetFlags() & SbxFlagBits::DontStore))
nElem++; nElem++;
} }
rStrm.WriteUInt16( nElem ); rStrm.WriteUInt16( nElem );
for( n = 0; n < mpVarEntries->size(); n++ ) for( sal_uInt32 n = 0; n < mpVarEntries->size(); n++ )
{ {
SbxVarEntry* pEntry = (*mpVarEntries)[n]; SbxVarEntry& rEntry = (*mpVarEntries)[n];
if (pEntry->mpVar && !(pEntry->mpVar->GetFlags() & SbxFlagBits::DontStore)) if (rEntry.mpVar && !(rEntry.mpVar->GetFlags() & SbxFlagBits::DontStore))
{ {
rStrm.WriteUInt16( n ); rStrm.WriteUInt16( n );
if (!pEntry->mpVar->Store(rStrm)) if (!rEntry.mpVar->Store(rStrm))
return false; return false;
} }
} }
......
...@@ -118,7 +118,7 @@ struct SbxVarEntry; ...@@ -118,7 +118,7 @@ struct SbxVarEntry;
class BASIC_DLLPUBLIC SbxArray : public SbxBase class BASIC_DLLPUBLIC SbxArray : public SbxBase
{ {
typedef std::vector<SbxVarEntry*> VarEntriesType; typedef std::vector<SbxVarEntry> VarEntriesType;
// #100883 Method to set method directly to parameter array // #100883 Method to set method directly to parameter array
friend class SbMethod; friend class SbMethod;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment