From 1db4ae96b1a1fa7c5b383a505a0b0b74b836551a Mon Sep 17 00:00:00 2001 From: starling13 Date: Sun, 7 Apr 2019 13:01:42 +0300 Subject: util/hex.h: Reserve result space in hex_encode() Reserve enough space for the result of hex_encode() to eliminate reallocations --- src/util/hex.h | 2 ++ 1 file changed, 2 insertions(+) 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'; -- cgit v1.2.3