summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-05-08 12:20:49 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-05-08 12:20:49 +0200
commitfe6cd734ad17fe838d9c080e1538db5d43272e49 (patch)
tree42a77cf7833fd766062431a06bb25a93e42a85c9
parent0daa634f2449f688e0c819d8c58a0389d0119abd (diff)
parent30d0dd43c58565809766683326535597f3dd39ea (diff)
downloadredot-engine-fe6cd734ad17fe838d9c080e1538db5d43272e49.tar.gz
Merge pull request #76748 from KoBeWi/has_feature(fast)
Cache feature list in `OS.has_feature()`
-rw-r--r--core/core_bind.cpp9
-rw-r--r--core/core_bind.h2
2 files changed, 10 insertions, 1 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 50587bb402..a13168beed 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 4138a85440..e34f8f3f5b 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<String, bool> feature_cache;
+
protected:
static void _bind_methods();
static OS *singleton;