mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 22:16:16 +02:00
avoid a string copy in printHash16
This commit is contained in:
parent
ccf7ce26fe
commit
a4dd87a2b3
1 changed files with 5 additions and 4 deletions
|
@ -71,12 +71,13 @@ const std::string base16Chars = "0123456789abcdef";
|
|||
|
||||
static std::string printHash16(const Hash & hash)
|
||||
{
|
||||
char buf[hash.hashSize * 2];
|
||||
std::string buf;
|
||||
buf.reserve(hash.hashSize * 2);
|
||||
for (unsigned int i = 0; i < hash.hashSize; i++) {
|
||||
buf[i * 2] = base16Chars[hash.hash[i] >> 4];
|
||||
buf[i * 2 + 1] = base16Chars[hash.hash[i] & 0x0f];
|
||||
buf.push_back(base16Chars[hash.hash[i] >> 4]);
|
||||
buf.push_back(base16Chars[hash.hash[i] & 0x0f]);
|
||||
}
|
||||
return std::string(buf, hash.hashSize * 2);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue