MCPcopy Create free account
hub / github.com/DFHack/dfhack / cache

Function cache

plugins/blueprint.cpp:240–244  ·  view source on GitHub ↗

We use const char * throughout this code instead of std::string to avoid having to allocate memory for all the small string literals. This significantly speeds up processing and allows us to handle very large maps (e.g. 16x16 embarks) without running out of memory. This cache provides a mechanism for storing dynamically created strings so their memory stays allocated until we write out the bluepri

Source from the content-addressed store, hash-verified

238// allocated until we write out the blueprints at the end.
239// If NULL is passed as the str, the cache is cleared.
240static const char * cache(const char *str) {
241 if (!str)
242 return NULL;
243 return string_cache.emplace(str).first->c_str();
244}
245
246// Convenience wrapper for std::string.
247static const char * cache(const string &str) {

Callers 8

add_markersFunction · 0.85
get_track_strFunction · 0.85
get_trap_strFunction · 0.85
add_speed_suffixFunction · 0.85
add_expansion_syntaxFunction · 0.85
get_tile_placeFunction · 0.85
get_tile_zoneFunction · 0.85

Calls 2

c_strMethod · 0.80
strMethod · 0.45

Tested by

no test coverage detected