Kaydet (Commit) aca98e59 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

add a way to restore from our new cache format

Change-Id: I6eeaaf9ca05bed2a908143ae5f4daab6e098799c
Reviewed-on: https://gerrit.libreoffice.org/41199Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst b1f6e629
......@@ -673,6 +673,7 @@ public:
void EnsureFormulaCellResults( SCROW nRow1, SCROW nRow2 );
void StoreToCache(SvStream& rStrm) const;
void RestoreFromCache(SvStream& rStrm);
#if DUMP_COLUMN_STORAGE
void DumpColumnStorage() const;
......
......@@ -2305,6 +2305,7 @@ public:
std::unique_ptr<sc::ColumnIterator> GetColumnIterator( SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const;
SC_DLLPUBLIC void StoreTabToCache(SCTAB nTab, SvStream& rStrm) const;
SC_DLLPUBLIC void RestoreTabFromCache(SCTAB nTab, SvStream& rStream);
#if DUMP_COLUMN_STORAGE
SC_DLLPUBLIC void DumpColumnStorage( SCTAB nTab, SCCOL nCol ) const;
......
......@@ -1010,6 +1010,8 @@ public:
void StoreToCache(SvStream& rStrm) const;
void RestoreFromCache(SvStream& rStrm);
#if DUMP_COLUMN_STORAGE
void DumpColumnStorage( SCCOL nCol ) const;
#endif
......
......@@ -49,6 +49,15 @@ void ScCacheTest::testCacheSimple()
SvMemoryStream aStrm;
aDoc.StoreTabToCache(0, aStrm);
aStrm.Seek(0);
ScDocument aNewDoc;
aNewDoc.InsertTab(0, "test");
aNewDoc.RestoreTabFromCache(0, aStrm);
for (SCROW nRow = 0; nRow < 10; ++nRow)
ASSERT_DOUBLES_EQUAL(nRow, aNewDoc.GetValue(0, nRow, 0));
}
void ScCacheTest::testCacheString()
......@@ -62,6 +71,16 @@ void ScCacheTest::testCacheString()
SvMemoryStream aStrm;
aDoc.StoreTabToCache(0, aStrm);
aStrm.Seek(0);
ScDocument aNewDoc;
aNewDoc.InsertTab(0, "test");
aNewDoc.RestoreTabFromCache(0, aStrm);
CPPUNIT_ASSERT_EQUAL(OUString("TestString"), aNewDoc.GetString(0, 0, 0));
CPPUNIT_ASSERT_EQUAL(OUString("asjdaonfdssda"), aNewDoc.GetString(0, 1, 0));
CPPUNIT_ASSERT_EQUAL(OUString("da"), aNewDoc.GetString(0, 2, 0));
}
CPPUNIT_TEST_SUITE_REGISTRATION(ScCacheTest);
......
......@@ -1708,4 +1708,63 @@ void ScColumn::StoreToCache(SvStream& rStrm) const
sc::ParseBlock(maCells.begin(), maCells, aFunc, (SCROW)0, nLastRow);
}
void ScColumn::RestoreFromCache(SvStream& rStrm)
{
sal_uInt64 nStoredCol = 0;
rStrm.ReadUInt64(nStoredCol);
if (nStoredCol != static_cast<sal_uInt64>(nCol))
throw std::exception();
sal_uInt64 nLastRow = 0;
rStrm.ReadUInt64(nLastRow);
sal_uInt64 nReadRow = 0;
while (nReadRow < nLastRow)
{
sal_uInt64 nStartRow = 0;
sal_uInt64 nDataSize = 0;
rStrm.ReadUInt64(nStartRow);
rStrm.ReadUInt64(nDataSize);
sal_uInt8 nType = 0;
rStrm.ReadUChar(nType);
switch (nType)
{
case 0:
// nothing to do
maCells.set_empty(nStartRow, nDataSize);
break;
case 1:
{
// nDataSize double values
std::vector<double> aValues(nDataSize);
for (SCROW nRow = 0; nRow < static_cast<SCROW>(nDataSize); ++nRow)
{
rStrm.ReadDouble(aValues[nRow]);
}
maCells.set(nStartRow, aValues.begin(), aValues.end());
}
break;
case 2:
{
std::vector<svl::SharedString> aStrings(nDataSize);
svl::SharedStringPool& rPool = pDocument->GetSharedStringPool();
for (SCROW nRow = 0; nRow < static_cast<SCROW>(nDataSize); ++nRow)
{
sal_Int32 nStrLength = 0;
rStrm.ReadInt32(nStrLength);
std::unique_ptr<char[]> pStr(new char[nStrLength]);
rStrm.ReadBytes(pStr.get(), nStrLength);
OString aOStr(pStr.get(), nStrLength);
OUString aStr = OStringToOUString(aOStr, RTL_TEXTENCODING_UTF8);
aStrings[nRow] = rPool.intern(aStr);
}
maCells.set(nStartRow, aStrings.begin(), aStrings.end());
}
break;
}
nReadRow += nDataSize;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -948,4 +948,13 @@ void ScDocument::StoreTabToCache(SCTAB nTab, SvStream& rStrm) const
pTab->StoreToCache(rStrm);
}
void ScDocument::RestoreTabFromCache(SCTAB nTab, SvStream& rStrm)
{
ScTable* pTab = FetchTable(nTab);
if (!pTab)
return;
pTab->RestoreFromCache(rStrm);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -433,4 +433,14 @@ void ScTable::StoreToCache(SvStream& rStrm) const
}
}
void ScTable::RestoreFromCache(SvStream& rStrm)
{
sal_uInt64 nCols = 0;
rStrm.ReadUInt64(nCols);
for (SCCOL nCol = 0; nCol < static_cast<SCCOL>(nCols); ++nCol)
{
aCol[nCol].RestoreFromCache(rStrm);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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