diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-01-29 23:35:34 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-01-30 11:57:00 -0500 |
commit | a0bd814fb5c2ed1d8a1583eb59c783290c7c3dc9 (patch) | |
tree | de2c5088bfedd77def56342bb8de53053fba9e78 /sc/source/core | |
parent | a28dc1dbedb32d18f8be4ef7eebff2281454e12b (diff) |
Speed up filling of random number generation over entire column.
Because nobody wants to wait forever...
Change-Id: Ie52bff944893b7e3fe9e7908be19d27c692fc1ea
Diffstat (limited to 'sc/source/core')
-rw-r--r-- | sc/source/core/data/cellvalues.cxx | 116 | ||||
-rw-r--r-- | sc/source/core/data/column4.cxx | 84 | ||||
-rw-r--r-- | sc/source/core/data/document10.cxx | 27 | ||||
-rw-r--r-- | sc/source/core/data/table7.cxx | 24 |
4 files changed, 251 insertions, 0 deletions
diff --git a/sc/source/core/data/cellvalues.cxx b/sc/source/core/data/cellvalues.cxx new file mode 100644 index 000000000000..5f7802e3625c --- /dev/null +++ b/sc/source/core/data/cellvalues.cxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <cellvalues.hxx> +#include <column.hxx> + +#include <cassert> +#include <boost/noncopyable.hpp> + +namespace sc { + +struct CellValuesImpl : boost::noncopyable +{ + CellStoreType maCells; +}; + +CellValues::CellValues() : + mpImpl(new CellValuesImpl) {} + +CellValues::~CellValues() +{ + delete mpImpl; +} + +void CellValues::transferFrom( ScColumn& rCol, SCROW nRow, size_t nLen ) +{ + mpImpl->maCells.resize(nLen); + rCol.maCells.transfer(nRow, nRow+nLen-1, mpImpl->maCells, 0); +} + +void CellValues::copyTo( ScColumn& rCol, SCROW nRow ) const +{ + CellStoreType& rDest = rCol.maCells; + const CellStoreType& rSrc = mpImpl->maCells; + + // Caller must ensure the destination is long enough. + assert(rSrc.size() + static_cast<size_t>(nRow) < rDest.size()); + + SCROW nCurRow = nRow; + CellStoreType::iterator itPos = rDest.begin(); + + CellStoreType::const_iterator itBlk = rSrc.begin(), itBlkEnd = rSrc.end(); + for (; itBlk != itBlkEnd; ++itBlk) + { + switch (itBlk->type) + { + case element_type_numeric: + { + numeric_block::const_iterator it = numeric_block::begin(*itBlk->data); + numeric_block::const_iterator itEnd = numeric_block::end(*itBlk->data); + itPos = rDest.set(itPos, nCurRow, it, itEnd); + } + break; + case element_type_string: + { + string_block::const_iterator it = string_block::begin(*itBlk->data); + string_block::const_iterator itEnd = string_block::end(*itBlk->data); + itPos = rDest.set(itPos, nCurRow, it, itEnd); + } + break; + case element_type_edittext: + { + edittext_block::const_iterator it = edittext_block::begin(*itBlk->data); + edittext_block::const_iterator itEnd = edittext_block::end(*itBlk->data); + std::vector<EditTextObject*> aVals; + aVals.reserve(itBlk->size); + for (; it != itEnd; ++it) + { + const EditTextObject* p = *it; + aVals.push_back(p->Clone()); + } + itPos = rDest.set(itPos, nCurRow, aVals.begin(), aVals.end()); + } + break; + case element_type_formula: + { + formula_block::const_iterator it = formula_block::begin(*itBlk->data); + formula_block::const_iterator itEnd = formula_block::end(*itBlk->data); + std::vector<ScFormulaCell*> aVals; + aVals.reserve(itBlk->size); + for (; it != itEnd; ++it) + { + const ScFormulaCell* p = *it; + aVals.push_back(p->Clone()); + } + itPos = rDest.set(itPos, nCurRow, aVals.begin(), aVals.end()); + } + break; + default: + itPos = rDest.set_empty(itPos, nCurRow, nCurRow+itBlk->size-1); + } + + nCurRow += itBlk->size; + } +} + +void CellValues::assign( const std::vector<double>& rVals ) +{ + mpImpl->maCells.resize(rVals.size()); + mpImpl->maCells.set(0, rVals.begin(), rVals.end()); +} + +size_t CellValues::size() const +{ + return mpImpl->maCells.size(); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx index b70e52d1920f..661c38db3a73 100644 --- a/sc/source/core/data/column4.cxx +++ b/sc/source/core/data/column4.cxx @@ -13,6 +13,7 @@ #include <cellvalue.hxx> #include <attarray.hxx> #include <document.hxx> +#include <cellvalues.hxx> #include <svl/sharedstring.hxx> @@ -144,4 +145,87 @@ void ScColumn::CopyOneCellFromClip( sc::CopyFromClipContext& rCxt, SCROW nRow1, } } +void ScColumn::SetValues( SCROW nRow, const std::vector<double>& rVals ) +{ + if (!ValidRow(nRow)) + return; + + SCROW nLastRow = nRow + rVals.size() - 1; + if (nLastRow > MAXROW) + // Out of bound. Do nothing. + return; + + sc::CellStoreType::position_type aPos = maCells.position(nRow); + DetachFormulaCells(aPos, rVals.size()); + + maCells.set(nRow, rVals.begin(), rVals.end()); + std::vector<sc::CellTextAttr> aDefaults(rVals.size()); + maCellTextAttrs.set(nRow, aDefaults.begin(), aDefaults.end()); + + CellStorageModified(); + + std::vector<SCROW> aRows; + aRows.reserve(rVals.size()); + for (SCROW i = nRow; i <= nLastRow; ++i) + aRows.push_back(i); + + BroadcastCells(aRows, SC_HINT_DATACHANGED); +} + +void ScColumn::TransferCellValuesTo( SCROW nRow, size_t nLen, sc::CellValues& rDest ) +{ + if (!ValidRow(nRow)) + return; + + SCROW nLastRow = nRow + nLen - 1; + if (nLastRow > MAXROW) + // Out of bound. Do nothing. + return; + + sc::CellStoreType::position_type aPos = maCells.position(nRow); + DetachFormulaCells(aPos, nLen); + + rDest.transferFrom(*this, nRow, nLen); + + std::vector<sc::CellTextAttr> aDefaults(nLen); + maCellTextAttrs.set(nRow, aDefaults.begin(), aDefaults.end()); + + CellStorageModified(); + + std::vector<SCROW> aRows; + aRows.reserve(nLen); + for (SCROW i = nRow; i <= nLastRow; ++i) + aRows.push_back(i); + + BroadcastCells(aRows, SC_HINT_DATACHANGED); +} + +void ScColumn::CopyCellValuesFrom( SCROW nRow, const sc::CellValues& rSrc ) +{ + if (!ValidRow(nRow)) + return; + + SCROW nLastRow = nRow + rSrc.size() - 1; + if (nLastRow > MAXROW) + // Out of bound. Do nothing + return; + + sc::CellStoreType::position_type aPos = maCells.position(nRow); + DetachFormulaCells(aPos, rSrc.size()); + + rSrc.copyTo(*this, nRow); + + std::vector<sc::CellTextAttr> aDefaults(rSrc.size()); + maCellTextAttrs.set(nRow, aDefaults.begin(), aDefaults.end()); + + CellStorageModified(); + + std::vector<SCROW> aRows; + aRows.reserve(rSrc.size()); + for (SCROW i = nRow; i <= nLastRow; ++i) + aRows.push_back(i); + + BroadcastCells(aRows, SC_HINT_DATACHANGED); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx index ee3e35d543a6..bd1e38526dcb 100644 --- a/sc/source/core/data/document10.cxx +++ b/sc/source/core/data/document10.cxx @@ -170,4 +170,31 @@ bool ScDocument::CopyOneCellFromClip( return true; } +void ScDocument::SetValues( const ScAddress& rPos, const std::vector<double>& rVals ) +{ + ScTable* pTab = FetchTable(rPos.Tab()); + if (!pTab) + return; + + pTab->SetValues(rPos.Col(), rPos.Row(), rVals); +} + +void ScDocument::TransferCellValuesTo( const ScAddress& rTopPos, size_t nLen, sc::CellValues& rDest ) +{ + ScTable* pTab = FetchTable(rTopPos.Tab()); + if (!pTab) + return; + + pTab->TransferCellValuesTo(rTopPos.Col(), rTopPos.Row(), nLen, rDest); +} + +void ScDocument::CopyCellValuesFrom( const ScAddress& rTopPos, const sc::CellValues& rSrc ) +{ + ScTable* pTab = FetchTable(rTopPos.Tab()); + if (!pTab) + return; + + pTab->CopyCellValuesFrom(rTopPos.Col(), rTopPos.Row(), rSrc); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/table7.cxx b/sc/source/core/data/table7.cxx index ac036aac2baf..8a7391c6e48e 100644 --- a/sc/source/core/data/table7.cxx +++ b/sc/source/core/data/table7.cxx @@ -24,4 +24,28 @@ void ScTable::CopyOneCellFromClip( aCol[nCol].CopyOneCellFromClip(rCxt, nRow1, nRow2); } +void ScTable::SetValues( SCCOL nCol, SCROW nRow, const std::vector<double>& rVals ) +{ + if (!ValidCol(nCol)) + return; + + aCol[nCol].SetValues(nRow, rVals); +} + +void ScTable::TransferCellValuesTo( SCCOL nCol, SCROW nRow, size_t nLen, sc::CellValues& rDest ) +{ + if (!ValidCol(nCol)) + return; + + aCol[nCol].TransferCellValuesTo(nRow, nLen, rDest); +} + +void ScTable::CopyCellValuesFrom( SCCOL nCol, SCROW nRow, const sc::CellValues& rSrc ) +{ + if (!ValidCol(nCol)) + return; + + aCol[nCol].CopyCellValuesFrom(nRow, rSrc); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |