[Libreoffice-commits] .: sc/inc sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Tue Jan 11 14:39:50 PST 2011
sc/inc/externalrefmgr.hxx | 2
sc/source/ui/docshell/externalrefmgr.cxx | 75 +++++++++++++++++++++----------
2 files changed, 54 insertions(+), 23 deletions(-)
New commits:
commit 5ec72c280f0993ee6c4684f5d74eabe39d680d86
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Tue Jan 11 17:38:24 2011 -0500
Properly cache range data from in-memory documents.
Failure to do this resulted in referenced external range data not
being saved to the document. This change fixes this.
diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx
index 8450900..10000a6 100644
--- a/sc/inc/externalrefmgr.hxx
+++ b/sc/inc/externalrefmgr.hxx
@@ -251,7 +251,7 @@ public:
ScMatrixRef mpRangeData;
};
void setCellRangeData(sal_uInt16 nFileId, const ScRange& rRange, const ::std::vector<SingleRangeData>& rData,
- TokenArrayRef pArray);
+ const TokenArrayRef& pArray);
bool isDocInitialized(sal_uInt16 nFileId);
void initializeDoc(sal_uInt16 nFileId, const ::std::vector<String>& rTabNames);
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 916b1b5..1237098 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -696,7 +696,7 @@ void ScExternalRefCache::setCellData(sal_uInt16 nFileId, const String& rTabName,
}
void ScExternalRefCache::setCellRangeData(sal_uInt16 nFileId, const ScRange& rRange, const vector<SingleRangeData>& rData,
- TokenArrayRef pArray)
+ const TokenArrayRef& pArray)
{
using ::std::pair;
if (rData.empty() || !isDocInitialized(nFileId))
@@ -1702,6 +1702,47 @@ ScExternalRefCache::TokenRef ScExternalRefManager::getSingleRefToken(
return pToken;
}
+namespace {
+
+/**
+ * Put the data into our internal cache table.
+ *
+ * @param rRefCache cache table set.
+ * @param pArray single range data to be returned.
+ * @param nFileId external file ID
+ * @param rTabName name of the table where the data should be cached.
+ * @param rCacheData range data to be cached.
+ * @param rCacheRange original cache range, including the empty region if
+ * any.
+ * @param rDataRange reduced cache range that includes only the non-empty
+ * data area.
+ */
+void putRangeDataIntoCache(
+ ScExternalRefCache& rRefCache, ScExternalRefCache::TokenArrayRef& pArray,
+ sal_uInt16 nFileId, const String& rTabName,
+ const vector<ScExternalRefCache::SingleRangeData>& rCacheData,
+ const ScRange& rCacheRange, const ScRange& rDataRange)
+{
+ if (pArray)
+ // Cache these values.
+ rRefCache.setCellRangeData(nFileId, rDataRange, rCacheData, pArray);
+ else
+ {
+ // Array is empty. Fill it with an empty matrix of the required size.
+ pArray.reset(lcl_fillEmptyMatrix(rCacheRange));
+
+ // Make sure to set this range 'cached', to prevent unnecessarily
+ // accessing the src document time and time again.
+ ScExternalRefCache::TableTypeRef pCacheTab =
+ rRefCache.getCacheTable(nFileId, rTabName, true, NULL);
+ if (pCacheTab)
+ pCacheTab->setCachedCellRange(
+ rCacheRange.aStart.Col(), rCacheRange.aStart.Row(), rCacheRange.aEnd.Col(), rCacheRange.aEnd.Row());
+ }
+}
+
+}
+
ScExternalRefCache::TokenArrayRef ScExternalRefManager::getDoubleRefTokens(
sal_uInt16 nFileId, const String& rTabName, const ScRange& rRange, const ScAddress* pCurPos)
{
@@ -1710,13 +1751,18 @@ ScExternalRefCache::TokenArrayRef ScExternalRefManager::getDoubleRefTokens(
maybeLinkExternalFile(nFileId);
- ScRange aRange(rRange);
+ ScRange aDataRange(rRange);
const ScDocument* pSrcDoc = getInMemorySrcDocument(nFileId);
if (pSrcDoc)
{
- // Document already loaded.
+ // Document already loaded in memory.
vector<ScExternalRefCache::SingleRangeData> aCacheData;
- return getDoubleRefTokensFromSrcDoc(pSrcDoc, rTabName, aRange, aCacheData);
+ ScExternalRefCache::TokenArrayRef pArray =
+ getDoubleRefTokensFromSrcDoc(pSrcDoc, rTabName, aDataRange, aCacheData);
+
+ // Put the data into cache.
+ putRangeDataIntoCache(maRefCache, pArray, nFileId, rTabName, aCacheData, rRange, aDataRange);
+ return pArray;
}
// Check if the given table name and the cell position is cached.
@@ -1736,25 +1782,10 @@ ScExternalRefCache::TokenArrayRef ScExternalRefManager::getDoubleRefTokens(
}
vector<ScExternalRefCache::SingleRangeData> aCacheData;
- pArray = getDoubleRefTokensFromSrcDoc(pSrcDoc, rTabName, aRange, aCacheData);
-
- if (pArray)
- // Cache these values.
- maRefCache.setCellRangeData(nFileId, aRange, aCacheData, pArray);
- else
- {
- // Array is empty. Fill it with an empty matrix of the required size.
- pArray.reset(lcl_fillEmptyMatrix(rRange));
-
- // Make sure to set this range 'cached', to prevent unnecessarily
- // accessing the src document time and time again.
- ScExternalRefCache::TableTypeRef pCacheTab =
- maRefCache.getCacheTable(nFileId, rTabName, true, NULL);
- if (pCacheTab)
- pCacheTab->setCachedCellRange(
- rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row());
- }
+ pArray = getDoubleRefTokensFromSrcDoc(pSrcDoc, rTabName, aDataRange, aCacheData);
+ // Put the data into cache.
+ putRangeDataIntoCache(maRefCache, pArray, nFileId, rTabName, aCacheData, rRange, aDataRange);
return pArray;
}
More information about the Libreoffice-commits
mailing list