mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-18 18:55:29 +02:00
util/hex.h: Reserve result space in hex_encode()
Reserve enough space for the result of hex_encode() to eliminate reallocations
This commit is contained in:
@@ -26,6 +26,8 @@ static const char hex_chars[] = "0123456789abcdef";
|
|||||||
static inline std::string hex_encode(const char *data, unsigned int data_size)
|
static inline std::string hex_encode(const char *data, unsigned int data_size)
|
||||||
{
|
{
|
||||||
std::string ret;
|
std::string ret;
|
||||||
|
ret.reserve(data_size * 2);
|
||||||
|
|
||||||
char buf2[3];
|
char buf2[3];
|
||||||
buf2[2] = '\0';
|
buf2[2] = '\0';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user