diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-07-27 23:20:29 +0300 |
---|---|---|
committer | Arkadiy Illarionov <qarkai@gmail.com> | 2019-07-30 11:16:00 +0200 |
commit | 5ba84c3c7080d55d86b8b39db077b6da36cb700a (patch) | |
tree | a71491f3d336a314ab63e834bd013f0503be967b /sccomp | |
parent | 850693273970be2662cce8f4d2710b3657a02f65 (diff) |
Simplify Sequence iterations in scaddins, sccomp, scripting
Use range-based loops, STL and comphelper functions
Change-Id: I836422a1c81a3dc9585687ed2e506eb59bb4ec91
Reviewed-on: https://gerrit.libreoffice.org/76484
Tested-by: Jenkins
Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com>
Diffstat (limited to 'sccomp')
-rw-r--r-- | sccomp/source/solver/CoinMPSolver.cxx | 17 | ||||
-rw-r--r-- | sccomp/source/solver/LpsolveSolver.cxx | 25 |
2 files changed, 18 insertions, 24 deletions
diff --git a/sccomp/source/solver/CoinMPSolver.cxx b/sccomp/source/solver/CoinMPSolver.cxx index cd2973580997..b422c3456875 100644 --- a/sccomp/source/solver/CoinMPSolver.cxx +++ b/sccomp/source/solver/CoinMPSolver.cxx @@ -63,10 +63,7 @@ void SAL_CALL CoinMPSolver::solve() // collect variables in vector (?) - std::vector<table::CellAddress> aVariableCells; - aVariableCells.reserve(maVariables.getLength()); - for (sal_Int32 nPos=0; nPos<maVariables.getLength(); nPos++) - aVariableCells.push_back( maVariables[nPos] ); + auto aVariableCells = comphelper::sequenceToContainer<std::vector<table::CellAddress>>(maVariables); size_t nVariables = aVariableCells.size(); size_t nVar = 0; @@ -75,12 +72,12 @@ void SAL_CALL CoinMPSolver::solve() ScSolverCellHashMap aCellsHash; aCellsHash[maObjective].reserve( nVariables + 1 ); // objective function - for (sal_Int32 nConstrPos = 0; nConstrPos < maConstraints.getLength(); ++nConstrPos) + for (const auto& rConstr : maConstraints) { - table::CellAddress aCellAddr = maConstraints[nConstrPos].Left; + table::CellAddress aCellAddr = rConstr.Left; aCellsHash[aCellAddr].reserve( nVariables + 1 ); // constraints: left hand side - if ( maConstraints[nConstrPos].Right >>= aCellAddr ) + if ( rConstr.Right >>= aCellAddr ) aCellsHash[aCellAddr].reserve( nVariables + 1 ); // constraints: right hand side } @@ -258,13 +255,13 @@ void SAL_CALL CoinMPSolver::solve() // apply single-var integer constraints - for (sal_Int32 nConstrPos = 0; nConstrPos < maConstraints.getLength(); ++nConstrPos) + for (const auto& rConstr : maConstraints) { - sheet::SolverConstraintOperator eOp = maConstraints[nConstrPos].Operator; + sheet::SolverConstraintOperator eOp = rConstr.Operator; if ( eOp == sheet::SolverConstraintOperator_INTEGER || eOp == sheet::SolverConstraintOperator_BINARY ) { - table::CellAddress aLeftAddr = maConstraints[nConstrPos].Left; + table::CellAddress aLeftAddr = rConstr.Left; // find variable index for cell for (nVar=0; nVar<nVariables; nVar++) if ( AddressEqual( aVariableCells[nVar], aLeftAddr ) ) diff --git a/sccomp/source/solver/LpsolveSolver.cxx b/sccomp/source/solver/LpsolveSolver.cxx index e20434a8cb46..62cded699758 100644 --- a/sccomp/source/solver/LpsolveSolver.cxx +++ b/sccomp/source/solver/LpsolveSolver.cxx @@ -98,10 +98,7 @@ void SAL_CALL LpsolveSolver::solve() // collect variables in vector (?) - std::vector<table::CellAddress> aVariableCells; - aVariableCells.reserve(maVariables.getLength()); - for (sal_Int32 nPos=0; nPos<maVariables.getLength(); nPos++) - aVariableCells.push_back( maVariables[nPos] ); + auto aVariableCells = comphelper::sequenceToContainer<std::vector<table::CellAddress>>(maVariables); size_t nVariables = aVariableCells.size(); size_t nVar = 0; @@ -110,12 +107,12 @@ void SAL_CALL LpsolveSolver::solve() ScSolverCellHashMap aCellsHash; aCellsHash[maObjective].reserve( nVariables + 1 ); // objective function - for (sal_Int32 nConstrPos = 0; nConstrPos < maConstraints.getLength(); ++nConstrPos) + for (const auto& rConstr : maConstraints) { - table::CellAddress aCellAddr = maConstraints[nConstrPos].Left; + table::CellAddress aCellAddr = rConstr.Left; aCellsHash[aCellAddr].reserve( nVariables + 1 ); // constraints: left hand side - if ( maConstraints[nConstrPos].Right >>= aCellAddr ) + if ( rConstr.Right >>= aCellAddr ) aCellsHash[aCellAddr].reserve( nVariables + 1 ); // constraints: right hand side } @@ -195,10 +192,10 @@ void SAL_CALL LpsolveSolver::solve() set_add_rowmode(lp, TRUE); - for (sal_Int32 nConstrPos = 0; nConstrPos < maConstraints.getLength(); ++nConstrPos) + for (const auto& rConstr : maConstraints) { // integer constraints are set later - sheet::SolverConstraintOperator eOp = maConstraints[nConstrPos].Operator; + sheet::SolverConstraintOperator eOp = rConstr.Operator; if ( eOp == sheet::SolverConstraintOperator_LESS_EQUAL || eOp == sheet::SolverConstraintOperator_GREATER_EQUAL || eOp == sheet::SolverConstraintOperator_EQUAL ) @@ -206,13 +203,13 @@ void SAL_CALL LpsolveSolver::solve() double fDirectValue = 0.0; bool bRightCell = false; table::CellAddress aRightAddr; - const uno::Any& rRightAny = maConstraints[nConstrPos].Right; + const uno::Any& rRightAny = rConstr.Right; if ( rRightAny >>= aRightAddr ) bRightCell = true; // cell specified as right-hand side else rRightAny >>= fDirectValue; // constant value - table::CellAddress aLeftAddr = maConstraints[nConstrPos].Left; + table::CellAddress aLeftAddr = rConstr.Left; const std::vector<double>& rLeftCoeff = aCellsHash[aLeftAddr]; std::unique_ptr<REAL[]> pValues(new REAL[nVariables+1] ); @@ -263,13 +260,13 @@ void SAL_CALL LpsolveSolver::solve() // apply single-var integer constraints - for (sal_Int32 nConstrPos = 0; nConstrPos < maConstraints.getLength(); ++nConstrPos) + for (const auto& rConstr : maConstraints) { - sheet::SolverConstraintOperator eOp = maConstraints[nConstrPos].Operator; + sheet::SolverConstraintOperator eOp = rConstr.Operator; if ( eOp == sheet::SolverConstraintOperator_INTEGER || eOp == sheet::SolverConstraintOperator_BINARY ) { - table::CellAddress aLeftAddr = maConstraints[nConstrPos].Left; + table::CellAddress aLeftAddr = rConstr.Left; // find variable index for cell for (nVar=0; nVar<nVariables; nVar++) if ( AddressEqual( aVariableCells[nVar], aLeftAddr ) ) |