Skip to content

Commit

Permalink
Merge pull request #76467 from RandomShaper/doc_cache_peace_of_mind
Browse files Browse the repository at this point in the history
Add peace-of-mind checks to API hash caching
  • Loading branch information
akien-mga committed Apr 26, 2023
2 parents fdb058f + a79e71a commit 51951a5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/object/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ClassDB::APIType ClassDB::current_api = API_CORE;
HashMap<ClassDB::APIType, uint64_t> ClassDB::api_hashes_cache;

void ClassDB::set_current_api(APIType p_api) {
DEV_ASSERT(!api_hashes_cache.has(p_api)); // This API type may not be suitable for caching of hash if it can change later.
current_api = p_api;
}

Expand Down Expand Up @@ -296,7 +297,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
}

hash = hash_fmix32(hash);
api_hashes_cache[p_api] = hash;

// Extension API changes at runtime; let's just not cache them by now.
if (p_api != API_EXTENSION && p_api != API_EDITOR_EXTENSION) {
api_hashes_cache[p_api] = hash;
}

return hash;
#else
return 0;
Expand Down

0 comments on commit 51951a5

Please sign in to comment.