sc/inc/address.hxx | 2 +- sc/qa/unit/ucalc.cxx | 36 ++++++++++++++++++++++-------------- sc/qa/unit/uicalc/uicalc.cxx | 10 +++++----- 3 files changed, 28 insertions(+), 20 deletions(-)
New commits: commit 373aa1961201a2d00c9886c21ee678a244960b24 Author: Luboš Luňák <[email protected]> AuthorDate: Wed Mar 30 11:58:04 2022 +0200 Commit: Luboš Luňák <[email protected]> CommitDate: Tue May 31 09:21:32 2022 +0200 reduce Calc's INITIALCOLCOUNT to 1 Columns should be dynamically allocated on demand, so there should be theoretically no good reason to allocate 64 initially. In practice doing so hides all places that do not allocate columns as needed. Change-Id: I8b46ecc97852ed23369e720f50f3266c48440435 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133311 Tested-by: Jenkins Reviewed-by: Luboš Luňák <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133800 Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx index 68bbe7dad075..8cf39ccfdf64 100644 --- a/sc/inc/address.hxx +++ b/sc/inc/address.hxx @@ -61,7 +61,7 @@ const SCSIZE SCSIZE_MAX = ::std::numeric_limits<SCSIZE>::max(); // Count values const SCROW MAXROWCOUNT = 1048576; const SCCOL MAXCOLCOUNT = 16384; -const SCCOL INITIALCOLCOUNT = 64; // initial number of columns we allocate memory for +const SCCOL INITIALCOLCOUNT = 1; // initial number of columns we allocate memory for /// limiting to 10000 for now, problem with 32 bit builds for now const SCTAB MAXTABCOUNT = 10000; // Maximum values diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index fbfa84fb0450..ff36fa0542ef 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -1413,48 +1413,55 @@ void Test::testIteratorsUnallocatedColumnsAttributes() { m_pDoc->InsertTab(0, "Tab1"); + // Set values in first two columns, to ensure allocation of those columns. + m_pDoc->SetValue(ScAddress(0,1,0), 1); + m_pDoc->SetValue(ScAddress(1,1,0), 2); + constexpr SCCOL allocatedColsCount = 2; + assert( allocatedColsCount >= INITIALCOLCOUNT ); + CPPUNIT_ASSERT_EQUAL(allocatedColsCount, m_pDoc->GetAllocatedColumnsCount(0)); + // Make entire second row and third row bold. ScPatternAttr boldAttr(m_pDoc->GetPool()); boldAttr.GetItemSet().Put(SvxWeightItem(WEIGHT_BOLD, ATTR_FONT_WEIGHT)); m_pDoc->ApplyPatternAreaTab(0, 1, m_pDoc->MaxCol(), 2, 0, boldAttr); // That shouldn't need allocating more columns, just changing the default attribute. - CPPUNIT_ASSERT_EQUAL(SCCOL(INITIALCOLCOUNT), m_pDoc->GetAllocatedColumnsCount(0)); + CPPUNIT_ASSERT_EQUAL(allocatedColsCount, m_pDoc->GetAllocatedColumnsCount(0)); vcl::Font aFont; const ScPatternAttr* pattern = m_pDoc->GetPattern(m_pDoc->MaxCol(), 1, 0); pattern->GetFont(aFont, SC_AUTOCOL_RAW); CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold", WEIGHT_BOLD, aFont.GetWeight()); // Test iterators. - ScDocAttrIterator docit( *m_pDoc, 0, INITIALCOLCOUNT - 1, 1, INITIALCOLCOUNT, 2 ); + ScDocAttrIterator docit( *m_pDoc, 0, allocatedColsCount - 1, 1, allocatedColsCount, 2 ); SCCOL col1, col2; SCROW row1, row2; CPPUNIT_ASSERT_EQUAL( pattern, docit.GetNext( col1, row1, row2 )); - CPPUNIT_ASSERT_EQUAL( SCCOL(INITIALCOLCOUNT - 1), col1 ); + CPPUNIT_ASSERT_EQUAL( SCCOL(allocatedColsCount - 1), col1 ); CPPUNIT_ASSERT_EQUAL( SCROW(1), row1 ); CPPUNIT_ASSERT_EQUAL( SCROW(2), row2 ); CPPUNIT_ASSERT_EQUAL( pattern, docit.GetNext( col1, row1, row2 )); - CPPUNIT_ASSERT_EQUAL( INITIALCOLCOUNT, col1 ); + CPPUNIT_ASSERT_EQUAL( allocatedColsCount, col1 ); CPPUNIT_ASSERT_EQUAL( SCROW(1), row1 ); CPPUNIT_ASSERT_EQUAL( SCROW(2), row2 ); CPPUNIT_ASSERT( docit.GetNext( col1, row1, row2 ) == nullptr ); - ScAttrRectIterator rectit( *m_pDoc, 0, INITIALCOLCOUNT - 1, 1, INITIALCOLCOUNT, 2 ); + ScAttrRectIterator rectit( *m_pDoc, 0, allocatedColsCount - 1, 1, allocatedColsCount, 2 ); CPPUNIT_ASSERT_EQUAL( pattern, rectit.GetNext( col1, col2, row1, row2 )); - CPPUNIT_ASSERT_EQUAL( SCCOL(INITIALCOLCOUNT - 1), col1 ); - CPPUNIT_ASSERT_EQUAL( INITIALCOLCOUNT, col2 ); + CPPUNIT_ASSERT_EQUAL( SCCOL(allocatedColsCount - 1), col1 ); + CPPUNIT_ASSERT_EQUAL( allocatedColsCount, col2 ); CPPUNIT_ASSERT_EQUAL( SCROW(1), row1 ); CPPUNIT_ASSERT_EQUAL( SCROW(2), row2 ); CPPUNIT_ASSERT( rectit.GetNext( col1, col2, row1, row2 ) == nullptr ); - ScHorizontalAttrIterator horit( *m_pDoc, 0, INITIALCOLCOUNT - 1, 1, INITIALCOLCOUNT, 2 ); + ScHorizontalAttrIterator horit( *m_pDoc, 0, allocatedColsCount - 1, 1, allocatedColsCount, 2 ); CPPUNIT_ASSERT_EQUAL( pattern, horit.GetNext( col1, col2, row1 )); - CPPUNIT_ASSERT_EQUAL( SCCOL(INITIALCOLCOUNT - 1), col1 ); - CPPUNIT_ASSERT_EQUAL( INITIALCOLCOUNT, col2 ); + CPPUNIT_ASSERT_EQUAL( SCCOL(allocatedColsCount - 1), col1 ); + CPPUNIT_ASSERT_EQUAL( allocatedColsCount, col2 ); CPPUNIT_ASSERT_EQUAL( SCROW(1), row1 ); CPPUNIT_ASSERT_EQUAL( pattern, horit.GetNext( col1, col2, row1 )); - CPPUNIT_ASSERT_EQUAL( SCCOL(INITIALCOLCOUNT - 1), col1 ); - CPPUNIT_ASSERT_EQUAL( INITIALCOLCOUNT, col2 ); + CPPUNIT_ASSERT_EQUAL( SCCOL(allocatedColsCount - 1), col1 ); + CPPUNIT_ASSERT_EQUAL( allocatedColsCount, col2 ); CPPUNIT_ASSERT_EQUAL( SCROW(2), row1 ); CPPUNIT_ASSERT( horit.GetNext( col1, col2, row1 ) == nullptr ); @@ -1516,12 +1523,13 @@ void Test::testLastChangedColFlagsWidth() m_pDoc->InsertTab(0, "Tab1"); constexpr SCCOL firstChangedCol = 100; - assert( firstChangedCol > INITIALCOLCOUNT ); + assert( firstChangedCol > m_pDoc->GetAllocatedColumnsCount(0)); + CPPUNIT_ASSERT_EQUAL(INITIALCOLCOUNT, m_pDoc->GetAllocatedColumnsCount(0)); for( SCCOL col = firstChangedCol; col <= m_pDoc->MaxCol(); ++col ) m_pDoc->SetColWidth( col, 0, 10 ); // That shouldn't need allocating more columns, just changing column flags. - CPPUNIT_ASSERT_EQUAL(SCCOL(INITIALCOLCOUNT), m_pDoc->GetAllocatedColumnsCount(0)); + CPPUNIT_ASSERT_EQUAL(INITIALCOLCOUNT, m_pDoc->GetAllocatedColumnsCount(0)); // But the flags are changed. CPPUNIT_ASSERT_EQUAL(m_pDoc->MaxCol(), m_pDoc->GetLastChangedColFlagsWidth(0)); diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx index bcecaf99d67e..9965d5ac6fa9 100644 --- a/sc/qa/unit/uicalc/uicalc.cxx +++ b/sc/qa/unit/uicalc/uicalc.cxx @@ -1943,15 +1943,15 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testUnallocatedColumnsAttributes) ScDocument* pDoc = pModelObj->GetDocument(); CPPUNIT_ASSERT(pDoc); - // If this check fails, this entire test needs adjusting. - CPPUNIT_ASSERT_EQUAL(SCCOL(64), pDoc->GetAllocatedColumnsCount(0)); + CPPUNIT_ASSERT_EQUAL(INITIALCOLCOUNT, pDoc->GetAllocatedColumnsCount(0)); - // Except for first 10 cells make the entire first row bold. - goToCell("K1:" + pDoc->MaxColAsString() + "1"); + // Except for first 1 cell make the entire first row bold. + assert(INITIALCOLCOUNT >= 1); + goToCell("B1:" + pDoc->MaxColAsString() + "1"); dispatchCommand(mxComponent, ".uno:Bold", {}); // That shouldn't need allocating more columns, just changing the default attribute. - CPPUNIT_ASSERT_EQUAL(SCCOL(64), pDoc->GetAllocatedColumnsCount(0)); + CPPUNIT_ASSERT_EQUAL(INITIALCOLCOUNT, pDoc->GetAllocatedColumnsCount(0)); vcl::Font aFont; pDoc->GetPattern(pDoc->MaxCol(), 0, 0)->GetFont(aFont, SC_AUTOCOL_RAW); CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold", WEIGHT_BOLD, aFont.GetWeight());
