From 352e36500c3973678e13ca875622fb5b928dbcb7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <>
Date: Sat, 5 Apr 2025 09:49:58 -0400
Subject: [PATCH] utils: make HexMap constexpr

---
 include/opendht/infohash.h | 6 +++---
 src/utils.cpp              | 2 --
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/include/opendht/infohash.h b/include/opendht/infohash.h
index a6fcede5..a7340209 100644
--- a/include/opendht/infohash.h
+++ b/include/opendht/infohash.h
@@ -110,7 +110,7 @@ public:
     bool operator!=(const Hash& h) const { return !(*this == h); }
 
     bool operator<(const Hash& o) const {
-        for(unsigned i = 0; i < N; i++) {
+        for (unsigned i = 0; i < N; i++) {
             if(data_[i] != o.data_[i])
                 return data_[i] < o.data_[i];
         }
@@ -119,7 +119,7 @@ public:
 
     Hash operator^(const Hash& o) const {
         Hash result;
-        for(auto i = 0u; i < N; i++) {
+        for (auto i = 0u; i < N; i++) {
             result[i] = data_[i] ^ o.data_[i];
         }
         return result;
@@ -356,7 +356,7 @@ private:
     static constexpr const char* hex_digits = "0123456789abcdef";
 };
 
-OPENDHT_PUBLIC extern const HexMap hex_map;
+OPENDHT_PUBLIC constexpr HexMap hex_map = {};
 
 inline std::string
 toHex(const uint8_t* data, size_t size) {
diff --git a/src/utils.cpp b/src/utils.cpp
index 4a4ada33..2af58854 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -39,8 +39,6 @@ const char* version() {
     return PACKAGE_VERSION;
 }
 
-const HexMap hex_map = {};
-
 static constexpr std::array<uint8_t, 12> MAPPED_IPV4_PREFIX {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff}};
 
 std::pair<std::string, std::string>
-- 
GitLab