- memset(getBlockNodeIdMapping_mapping, 0xFF, (USHRT_MAX + 1) * sizeof(content_t));
-
- std::set<content_t> unknown_contents;
+ // The static memory requires about 65535 * sizeof(int) RAM in order to be
+ // sure we can handle all content ids. But it's absolutely worth it as it's
+ // a speedup of 4 for one of the major time consuming functions on storing
+ // mapblocks.
+ thread_local std::unique_ptr<content_t[]> mapping;
+ static_assert(sizeof(content_t) == 2, "content_t must be 16-bit");
+ if (!mapping)
+ mapping = std::make_unique<content_t[]>(USHRT_MAX + 1);
+
+ memset(mapping.get(), 0xFF, (USHRT_MAX + 1) * sizeof(content_t));
+
+ std::unordered_set<content_t> unknown_contents;