Skip to content

Commit 2722a1f

Browse files
committed
Merge #13383: bench: Use non-throwing ParseDouble(...) instead of throwing boost::lexical_cast<double>(...)
f41d339 bench: Use non-throwing ParseDouble(...) instead of throwing boost::lexical_cast<double>(...) (practicalswift) Pull request description: * Non-Boost is better than Boost. * Non-throwing is better than throwing. * Explicit error handling is better than implicit error handling. * `ParseDouble(…)` deserves to be used outside of its unit tests :-) Tree-SHA512: a8cf04a5f8363cb7ced0bcaf1fed00e1e5dd6a63a6c11e5f0ba4e5c845b0df7c2b050d887075f158cd62dc7e02843ecaafc15e42e383c066461c6d7399e06b49
2 parents f014933 + f41d339 commit 2722a1f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/bench/bench_bitcoin.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
#include <crypto/sha256.h>
88
#include <key.h>
9-
#include <validation.h>
10-
#include <util.h>
119
#include <random.h>
12-
13-
#include <boost/lexical_cast.hpp>
10+
#include <util.h>
11+
#include <utilstrencodings.h>
12+
#include <validation.h>
1413

1514
#include <memory>
1615

@@ -64,8 +63,11 @@ int main(int argc, char** argv)
6463
std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING);
6564
bool is_list_only = gArgs.GetBoolArg("-list", false);
6665

67-
double scaling_factor = boost::lexical_cast<double>(scaling_str);
68-
66+
double scaling_factor;
67+
if (!ParseDouble(scaling_str, &scaling_factor)) {
68+
fprintf(stderr, "Error parsing scaling factor as double: %s\n", scaling_str.c_str());
69+
return EXIT_FAILURE;
70+
}
6971

7072
std::unique_ptr<benchmark::Printer> printer(new benchmark::ConsolePrinter());
7173
std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER);

0 commit comments

Comments
 (0)