Use std::array.

This commit is contained in:
chriseth 2015-05-06 13:56:40 +02:00
parent c3e5fe6a12
commit c731ae92ca
2 changed files with 8 additions and 5 deletions

View File

@ -31,7 +31,7 @@ using namespace dev;
using namespace dev::eth; using namespace dev::eth;
using namespace dev::solidity; using namespace dev::solidity;
map<ASTNode const*, GasMeter::GasConsumption[2]> StructuralGasEstimator::performEstimation( StructuralGasEstimator::ASTGasConsumptionSelfAccumulated StructuralGasEstimator::performEstimation(
AssemblyItems const& _items, AssemblyItems const& _items,
vector<ASTNode const*> const& _ast vector<ASTNode const*> const& _ast
) )
@ -42,7 +42,7 @@ map<ASTNode const*, GasMeter::GasConsumption[2]> StructuralGasEstimator::perform
for (auto const& item: _items) for (auto const& item: _items)
particularCosts[item.getLocation()] += meter.estimateMax(item); particularCosts[item.getLocation()] += meter.estimateMax(item);
map<ASTNode const*, GasMeter::GasConsumption[2]> gasCosts; ASTGasConsumptionSelfAccumulated gasCosts;
auto onNode = [&](ASTNode const& _node) auto onNode = [&](ASTNode const& _node)
{ {
gasCosts[&_node][0] = gasCosts[&_node][1] = particularCosts[_node.getLocation()]; gasCosts[&_node][0] = gasCosts[&_node][1] = particularCosts[_node.getLocation()];
@ -60,7 +60,7 @@ map<ASTNode const*, GasMeter::GasConsumption[2]> StructuralGasEstimator::perform
} }
map<ASTNode const*, GasMeter::GasConsumption> StructuralGasEstimator::breakToStatementLevel( map<ASTNode const*, GasMeter::GasConsumption> StructuralGasEstimator::breakToStatementLevel(
map<ASTNode const*, GasMeter::GasConsumption[2]> const& _gasCosts, ASTGasConsumptionSelfAccumulated const& _gasCosts,
vector<ASTNode const*> const& _roots vector<ASTNode const*> const& _roots
) )
{ {

View File

@ -24,6 +24,7 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <array>
#include <libsolidity/ASTForward.h> #include <libsolidity/ASTForward.h>
#include <libevmasm/GasMeter.h> #include <libevmasm/GasMeter.h>
#include <libevmasm/Assembly.h> #include <libevmasm/Assembly.h>
@ -37,11 +38,13 @@ class StructuralGasEstimator
{ {
public: public:
using ASTGasConsumption = std::map<ASTNode const*, eth::GasMeter::GasConsumption>; using ASTGasConsumption = std::map<ASTNode const*, eth::GasMeter::GasConsumption>;
using ASTGasConsumptionSelfAccumulated =
std::map<ASTNode const*, std::array<eth::GasMeter::GasConsumption, 2>>;
/// Estimates the gas consumption for every assembly item in the given assembly and stores /// Estimates the gas consumption for every assembly item in the given assembly and stores
/// it by source location. /// it by source location.
/// @returns a mapping from each AST node to a pair of its particular and syntactically accumulated gas costs. /// @returns a mapping from each AST node to a pair of its particular and syntactically accumulated gas costs.
std::map<ASTNode const*, eth::GasMeter::GasConsumption[2]> performEstimation( ASTGasConsumptionSelfAccumulated performEstimation(
eth::AssemblyItems const& _items, eth::AssemblyItems const& _items,
std::vector<ASTNode const*> const& _ast std::vector<ASTNode const*> const& _ast
); );
@ -50,7 +53,7 @@ public:
/// 1. source locations of statements that do not contain other statements /// 1. source locations of statements that do not contain other statements
/// 2. maximal source locations that do not overlap locations coming from the first rule /// 2. maximal source locations that do not overlap locations coming from the first rule
ASTGasConsumption breakToStatementLevel( ASTGasConsumption breakToStatementLevel(
std::map<ASTNode const*, eth::GasMeter::GasConsumption[2]> const& _gasCosts, ASTGasConsumptionSelfAccumulated const& _gasCosts,
std::vector<ASTNode const*> const& _roots std::vector<ASTNode const*> const& _roots
); );
}; };