sc/qa/unit/ucalc_formula.cxx | 6 ++++++ sc/source/core/data/column2.cxx | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-)
New commits: commit f518cd28d7ebacf059ca826353c8202c87be957f Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Tue Oct 29 21:52:09 2013 -0400 Restore the old behavior, even when the data comes from a cache. Change-Id: I722a53ee0e8a8f757c1d02fa5f604e6ccedf3b1a diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index e87878a..ce9ce2e 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -229,6 +229,12 @@ void Test::testFetchVectorRefArray() CPPUNIT_ASSERT_MESSAGE("This should be empty.", isEmpty(aArray, 8)); CPPUNIT_ASSERT_MESSAGE("This should be empty.", isEmpty(aArray, 9)); + // Get the array for F3:F4. This array should only consist of numeric array. + aArray = m_pDoc->FetchVectorRefArray(ScAddress(5,2,0), 3); + CPPUNIT_ASSERT_MESSAGE("Failed to fetch vector ref array.", aArray.isValid()); + CPPUNIT_ASSERT_MESSAGE("Array should have a numeric array.", aArray.mpNumericArray); + CPPUNIT_ASSERT_MESSAGE("Array should NOT have a string array.", !aArray.mpStringArray); + m_pDoc->DeleteTab(0); } diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index aff16d5..c7b8f26 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -2614,6 +2614,36 @@ copyFirstFormulaBlock( return rCxt.setCachedColArray(nTab, nCol, pNumArray, pStrArray); } +struct FiniteValueFinder : std::unary_function<double, bool> +{ + bool operator() (double f) const { return !rtl::math::isNan(f); } +}; + +struct NonNullStringFinder : std::unary_function<const rtl_uString*, bool> +{ + bool operator() (const rtl_uString* p) const { return p != NULL; } +}; + +bool hasNonEmpty( const sc::FormulaGroupContext::NumArrayType& rArray, SCROW nRow1, SCROW nRow2 ) +{ + // The caller has to make sure the array is at least nRow2+1 long. + sc::FormulaGroupContext::NumArrayType::const_iterator it = rArray.begin(); + std::advance(it, nRow1); + sc::FormulaGroupContext::NumArrayType::const_iterator itEnd = it; + std::advance(itEnd, nRow2-nRow1+1); + return std::find_if(it, itEnd, FiniteValueFinder()) != itEnd; +} + +bool hasNonEmpty( const sc::FormulaGroupContext::StrArrayType& rArray, SCROW nRow1, SCROW nRow2 ) +{ + // The caller has to make sure the array is at least nRow2+1 long. + sc::FormulaGroupContext::StrArrayType::const_iterator it = rArray.begin(); + std::advance(it, nRow1); + sc::FormulaGroupContext::StrArrayType::const_iterator itEnd = it; + std::advance(itEnd, nRow2-nRow1+1); + return std::find_if(it, itEnd, NonNullStringFinder()) != itEnd; +} + } formula::VectorRefArray ScColumn::FetchVectorRefArray( SCROW nRow1, SCROW nRow2 ) @@ -2627,11 +2657,11 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( SCROW nRow1, SCROW nRow2 if (pColArray) { const double* pNum = NULL; - if (pColArray->mpNumArray) + if (pColArray->mpNumArray && hasNonEmpty(*pColArray->mpNumArray, nRow1, nRow2)) pNum = &(*pColArray->mpNumArray)[nRow1]; rtl_uString** pStr = NULL; - if (pColArray->mpStrArray) + if (pColArray->mpStrArray && hasNonEmpty(*pColArray->mpStrArray, nRow1, nRow2)) pStr = &(*pColArray->mpStrArray)[nRow1]; return formula::VectorRefArray(pNum, pStr); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits