mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 14:45:08 +01:00
Preallocate result in TryParseHex
to avoid resizing
Running `make && ./src/bench/bench_bitcoin -filter=HexParse` a few times results in: ``` | ns/base16 | base16/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 0.68 | 1,465,555,976.27 | 0.8% | 0.01 | `HexParse` | 0.68 | 1,472,962,920.18 | 0.3% | 0.01 | `HexParse` | 0.68 | 1,476,159,423.00 | 0.3% | 0.01 | `HexParse` ```
This commit is contained in:
parent
b7489ecb52
commit
a19235c14b
@ -81,6 +81,8 @@ template <typename Byte>
|
||||
std::optional<std::vector<Byte>> TryParseHex(std::string_view str)
|
||||
{
|
||||
std::vector<Byte> vch;
|
||||
vch.reserve(str.size() / 2); // two hex characters form a single byte
|
||||
|
||||
auto it = str.begin();
|
||||
while (it != str.end()) {
|
||||
if (IsSpace(*it)) {
|
||||
|
Loading…
Reference in New Issue
Block a user