Skip to content

Commit d5bae3f

Browse files
committed
TestFunctionCall::formatGasExpectations(): Helper for getting optional values from a map
1 parent cd94139 commit d5bae3f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

test/libsolidity/util/TestFunctionCall.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,16 @@ std::string formatGasDiff(std::optional<u256> const& _gasUsed, std::optional<u25
353353
return fmt::format("{} ({:+}%)", difference.str(), percent);
354354
}
355355

356+
// TODO: Convert this into a generic helper for getting optional form a map
357+
std::optional<u256> gasOrNullopt(std::map<std::string, u256> const& _map, std::string const& _key)
358+
{
359+
auto it = _map.find(_key);
360+
if (it == _map.end())
361+
return std::nullopt;
362+
363+
return it->second;
364+
}
365+
356366
}
357367

358368
std::string TestFunctionCall::formatGasExpectations(
@@ -368,8 +378,8 @@ std::string TestFunctionCall::formatGasExpectations(
368378

369379
os << std::endl << _linePrefix << "// gas " << runType << ": " << gasUsed.str();
370380
std::string gasDiff = formatGasDiff(
371-
m_gasCosts.count(runType) > 0 ? std::make_optional<u256>(m_gasCosts.at(runType)) : std::nullopt,
372-
m_call.expectations.gasUsed.count(runType) > 0 ? std::make_optional<u256>(m_call.expectations.gasUsed.at(runType)) : std::nullopt
381+
gasOrNullopt(m_gasCosts, runType),
382+
gasOrNullopt(m_call.expectations.gasUsed, runType)
373383
);
374384
if (_showDifference && !gasDiff.empty() && _useActualCost)
375385
os << " [" << gasDiff << "]";

0 commit comments

Comments
 (0)