Let's return to our original get_bitmap_resource() function, the std::string originally used is exchanged to a PrehashedString:
// Bitmap cache auto get_bitmap_resource(const PrehashedString& path) -> const Bitmap& { // Static storage of all loaded bitmaps static auto loaded_bitmaps = std::unordered_map<PrehashedString, Bitmap>{}; // If the bitmap is already in loaded_bitmaps, return it if (loaded_bitmaps.count(path) > 0) { return loaded_bitmaps.at(path).second; } // The bitmap isn't already loaded, load and return it auto bitmap = load_bitmap_from_filesystem(path.c_str()); loaded_bitmaps.emplace(path, std::move(bitmap)); return loaded_bitmaps.at(path); }
We also need a function ...