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]>
diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx
index 13cfd9c..a1fb7e3 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 8da0c61..b35d88e 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1415,48 +1415,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 );

@@ -1519,12 +1526,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 2d3f48a..46d8917 100644
--- a/sc/qa/unit/uicalc/uicalc.cxx
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -2899,15 +2899,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());