util/hex.h: Reserve result space in hex_encode()
authorstarling13 <starling13@mail.ru>
Sun, 7 Apr 2019 10:01:42 +0000 (13:01 +0300)
committerSmallJoker <SmallJoker@users.noreply.github.com>
Sun, 7 Apr 2019 10:01:42 +0000 (12:01 +0200)
Reserve enough space for the result of hex_encode() to eliminate reallocations

src/util/hex.h

index df22539a52673c02c996839de70d1ba522e23329..31bcaa2baad575b2affbd15f137956401e89e2a8 100644 (file)
@@ -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';