diff --git a/include/opendht/utils.h b/include/opendht/utils.h
index 4836fd65e7ea2a002f250b8e95e39eb9cbe626b7..93b6e8d98dd0c75efa5eab480500cf3bbb174559 100644
--- a/include/opendht/utils.h
+++ b/include/opendht/utils.h
@@ -173,7 +173,13 @@ unpackMsg(Blob b) {
 
 msgpack::unpacked unpackMsg(Blob b);
 
-msgpack::object* findMapValue(const msgpack::object& map, const char* key);
-msgpack::object* findMapValue(const msgpack::object& map, const std::string& key);
+msgpack::object* findMapValue(const msgpack::object& map, const char* key, size_t length);
+
+inline msgpack::object* findMapValue(const msgpack::object& map, const char* key) {
+    return findMapValue(map, key, strlen(key));
+}
+inline msgpack::object* findMapValue(const msgpack::object& map, const std::string& key) {
+    return findMapValue(map, key.c_str(), key.size());
+}
 
 } // namespace dht
diff --git a/src/utils.cpp b/src/utils.cpp
index 90efca778a960be549fe1917f30273df2ad967fe..be69eac0da5a7794f65749e3f89c172d011bf4e8 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -277,28 +277,16 @@ unpackMsg(Blob b) {
 }
 
 msgpack::object*
-findMapValue(const msgpack::object& map, const char* key) {
+findMapValue(const msgpack::object& map, const char* key, size_t key_length) {
     if (map.type != msgpack::type::MAP) throw msgpack::type_error();
     for (unsigned i = 0; i < map.via.map.size; i++) {
         auto& o = map.via.map.ptr[i];
         if (o.key.type == msgpack::type::STR
+            && key_length == o.key.via.str.size
             && std::strncmp(o.key.via.str.ptr, key, o.key.via.str.size) == 0)
             return &o.val;
     }
     return nullptr;
 }
 
-msgpack::object*
-findMapValue(const msgpack::object& map, const std::string& key) {
-    if (map.type != msgpack::type::MAP) throw msgpack::type_error();
-    for (unsigned i = 0; i < map.via.map.size; i++) {
-        auto& o = map.via.map.ptr[i];
-        if (o.key.type == msgpack::type::STR
-            && key.size() == o.key.via.str.size
-            && std::strncmp(o.key.via.str.ptr, key.data(), o.key.via.str.size) == 0)
-            return &o.val;
-    }
-    return nullptr;
-}
-
 }