Skip to content

Commit

Permalink
uint256: replace sprintf with HexStr and reverse-iterator
Browse files Browse the repository at this point in the history
Instead of calling sprintf for every byte, format the hex bytes
ourselves by help of HexStr and a reverse_iterator.
  • Loading branch information
laanwj committed Feb 27, 2017
1 parent 6206252 commit 0a17714
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/uint256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ base_blob<BITS>::base_blob(const std::vector<unsigned char>& vch)
template <unsigned int BITS>
std::string base_blob<BITS>::GetHex() const
{
char psz[sizeof(data) * 2 + 1];
for (unsigned int i = 0; i < sizeof(data); i++)
sprintf(psz + i * 2, "%02x", data[sizeof(data) - i - 1]);
return std::string(psz, psz + sizeof(data) * 2);
return HexStr(std::reverse_iterator<const uint8_t*>(data + sizeof(data)), std::reverse_iterator<const uint8_t*>(data));
}

template <unsigned int BITS>
Expand Down

0 comments on commit 0a17714

Please sign in to comment.