From: starling13 Date: Sun, 7 Apr 2019 10:01:42 +0000 (+0300) Subject: util/hex.h: Reserve result space in hex_encode() X-Git-Tag: 5.1.0~250 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=1db4ae96b1a1fa7c5b383a505a0b0b74b836551a;p=oweals%2Fminetest.git util/hex.h: Reserve result space in hex_encode() Reserve enough space for the result of hex_encode() to eliminate reallocations --- diff --git a/src/util/hex.h b/src/util/hex.h index df22539a5..31bcaa2ba 100644 --- a/src/util/hex.h +++ b/src/util/hex.h @@ -26,6 +26,8 @@ static const char hex_chars[] = "0123456789abcdef"; static inline std::string hex_encode(const char *data, unsigned int data_size) { std::string ret; + ret.reserve(data_size * 2); + char buf2[3]; buf2[2] = '\0';