From 30d0dd43c58565809766683326535597f3dd39ea Mon Sep 17 00:00:00 2001 From: kobewi Date: Fri, 5 May 2023 15:23:25 +0200 Subject: [PATCH] Cache feature list in OS.has_feature() --- core/core_bind.cpp | 9 ++++++++- core/core_bind.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 50587bb4026..a13168beed7 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -423,7 +423,14 @@ Error OS::set_thread_name(const String &p_name) { }; bool OS::has_feature(const String &p_feature) const { - return ::OS::get_singleton()->has_feature(p_feature); + const bool *value_ptr = feature_cache.getptr(p_feature); + if (value_ptr) { + return *value_ptr; + } else { + const bool has = ::OS::get_singleton()->has_feature(p_feature); + feature_cache[p_feature] = has; + return has; + } } uint64_t OS::get_static_memory_usage() const { diff --git a/core/core_bind.h b/core/core_bind.h index 4138a854407..e34f8f3f5b9 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -119,6 +119,8 @@ public: class OS : public Object { GDCLASS(OS, Object); + mutable HashMap feature_cache; + protected: static void _bind_methods(); static OS *singleton;