diff options
author | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-01-12 21:19:05 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-01-12 21:51:52 -0500 |
commit | 65d58adcec970306ac641f49f56404b6be0e1462 (patch) | |
tree | 5eb3d2ff10f1637002a0dcf600e92ef3522eefe2 /sc/source | |
parent | e6392d2a17c0bee792cfd0060d177e5c6a71f346 (diff) |
fdo#43077: Finally, remove data cache when nobody references it.
Also, removed unnecessary reloading of the whole table data when
reference is updated.
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/data/dpobject.cxx | 70 | ||||
-rw-r--r-- | sc/source/core/data/dptablecache.cxx | 3 |
2 files changed, 66 insertions, 7 deletions
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index 3332ec99f423..bc26c48d61f1 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -774,11 +774,8 @@ void ScDPObject::UpdateReference( UpdateRefMode eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 ); if ( eRes != UR_NOTHING ) { - ScSheetSourceDesc aNewDesc(pDoc); - aNewDesc.SetSourceRange(ScRange(nCol1, nRow1, nTab1, nCol2, nRow2, nTab2)); - - SCsCOL nDiffX = nCol1 - (SCsCOL) pSheetDesc->GetSourceRange().aStart.Col(); - SCsROW nDiffY = nRow1 - (SCsROW) pSheetDesc->GetSourceRange().aStart.Row(); + SCsCOL nDiffX = nCol1 - pSheetDesc->GetSourceRange().aStart.Col(); + SCsROW nDiffY = nRow1 - pSheetDesc->GetSourceRange().aStart.Row(); ScQueryParam aParam = pSheetDesc->GetQueryParam(); aParam.nCol1 = sal::static_int_cast<SCCOL>( aParam.nCol1 + nDiffX ); @@ -790,8 +787,8 @@ void ScDPObject::UpdateReference( UpdateRefMode eUpdateRefMode, if (aParam.GetEntry(i).bDoQuery) aParam.GetEntry(i).nField += nDiffX; - aNewDesc.SetQueryParam(aParam); - SetSheetDesc( aNewDesc ); // allocates new pSheetDesc + pSheetDesc->SetQueryParam(aParam); + pSheetDesc->SetSourceRange(ScRange(nCol1, nRow1, nTab1, nCol2, nRow2, nTab2)); } } } @@ -2610,6 +2607,22 @@ void ScDPCollection::SheetCaches::removeCache(const ScRange& rRange) maCaches.erase(itCache); } +bool ScDPCollection::SheetCaches::remove(const ScDPCache* p) +{ + CachesType::iterator it = maCaches.begin(), itEnd = maCaches.end(); + for (; it != itEnd; ++it) + { + if (it->second == p) + { + size_t idx = it->first; + maCaches.erase(it); + maRanges[idx].SetInvalid(); + return true; + } + } + return false; +} + ScDPCollection::NameCaches::NameCaches(ScDocument* pDoc) : mpDoc(pDoc) {} bool ScDPCollection::NameCaches::hasCache(const OUString& rName) const @@ -2655,6 +2668,20 @@ void ScDPCollection::NameCaches::removeCache(const OUString& rName) maCaches.erase(itr); } +bool ScDPCollection::NameCaches::remove(const ScDPCache* p) +{ + CachesType::iterator it = maCaches.begin(), itEnd = maCaches.end(); + for (; it != itEnd; ++it) + { + if (it->second == p) + { + maCaches.erase(it); + return true; + } + } + return false; +} + ScDPCollection::DBType::DBType(sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand) : mnSdbType(nSdbType), maDBName(rDBName), maCommand(rCommand) {} @@ -2794,6 +2821,20 @@ void ScDPCollection::DBCaches::removeCache(sal_Int32 nSdbType, const OUString& r maCaches.erase(itr); } +bool ScDPCollection::DBCaches::remove(const ScDPCache* p) +{ + CachesType::iterator it = maCaches.begin(), itEnd = maCaches.end(); + for (; it != itEnd; ++it) + { + if (it->second == p) + { + maCaches.erase(it); + return true; + } + } + return false; +} + ScDPCollection::ScDPCollection(ScDocument* pDocument) : pDoc( pDocument ), maSheetCaches(pDocument), @@ -3080,6 +3121,21 @@ ScDPCollection::DBCaches& ScDPCollection::GetDBCaches() return maDBCaches; } +void ScDPCollection::RemoveCache(const ScDPCache* pCache) +{ + if (maSheetCaches.remove(pCache)) + // sheet cache removed. + return; + + if (maNameCaches.remove(pCache)) + // named range cache removed. + return; + + if (maDBCaches.remove(pCache)) + // database cache removed. + return; +} + bool operator<(const ScDPCollection::DBType& left, const ScDPCollection::DBType& right) { if (left.mnSdbType != right.mnSdbType) diff --git a/sc/source/core/data/dptablecache.cxx b/sc/source/core/data/dptablecache.cxx index 4ce51952d578..57f6ce18cda1 100644 --- a/sc/source/core/data/dptablecache.cxx +++ b/sc/source/core/data/dptablecache.cxx @@ -37,6 +37,7 @@ #include "queryparam.hxx" #include "dpglobal.hxx" #include "dptabdat.hxx" +#include "dpobject.hxx" #include "docoptio.hxx" #include <unotools/textsearch.hxx> @@ -993,6 +994,8 @@ void ScDPCache::AddReference(ScDPObject* pObj) const void ScDPCache::RemoveReference(ScDPObject* pObj) const { maRefObjects.erase(pObj); + if (maRefObjects.empty()) + mpDoc->GetDPCollection()->RemoveCache(this); } const ScDPCache::ObjectSetType& ScDPCache::GetAllReferences() const |