Skip to content

Commit 955cafa

Browse files
committed
Inline static variables (part 2)
1 parent 19bb187 commit 955cafa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+120
-346
lines changed

core/io/resource.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -613,16 +613,6 @@ Resource::~Resource() {
613613
}
614614
}
615615

616-
HashMap<String, Resource *> ResourceCache::resources;
617-
#ifdef TOOLS_ENABLED
618-
HashMap<String, HashMap<String, String>> ResourceCache::resource_path_cache;
619-
#endif
620-
621-
Mutex ResourceCache::lock;
622-
#ifdef TOOLS_ENABLED
623-
RWLock ResourceCache::path_cache_lock;
624-
#endif
625-
626616
void ResourceCache::clear() {
627617
if (!resources.is_empty()) {
628618
if (OS::get_singleton()->is_stdout_verbose()) {

core/io/resource.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ class Resource : public RefCounted {
171171
class ResourceCache {
172172
friend class Resource;
173173
friend class ResourceLoader; //need the lock
174-
static Mutex lock;
175-
static HashMap<String, Resource *> resources;
174+
static inline Mutex lock;
175+
static inline HashMap<String, Resource *> resources;
176176
#ifdef TOOLS_ENABLED
177-
static HashMap<String, HashMap<String, String>> resource_path_cache; // Each tscn has a set of resource paths and IDs.
178-
static RWLock path_cache_lock;
177+
static inline HashMap<String, HashMap<String, String>> resource_path_cache; // Each tscn has a set of resource paths and IDs.
178+
static inline RWLock path_cache_lock;
179179
#endif // TOOLS_ENABLED
180180
friend void unregister_core_types();
181181
static void clear();

core/io/resource_loader.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@
5151
#define print_lt(m_text)
5252
#endif
5353

54-
Ref<ResourceFormatLoader> ResourceLoader::loader[ResourceLoader::MAX_LOADERS];
55-
56-
int ResourceLoader::loader_count = 0;
57-
5854
bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_for_type) const {
5955
bool ret = false;
6056
if (GDVIRTUAL_CALL(_recognize_path, p_path, p_for_type, ret)) {
@@ -1418,8 +1414,6 @@ void ResourceLoader::set_load_callback(ResourceLoadedCallback p_callback) {
14181414
_loaded_callback = p_callback;
14191415
}
14201416

1421-
ResourceLoadedCallback ResourceLoader::_loaded_callback = nullptr;
1422-
14231417
Ref<ResourceFormatLoader> ResourceLoader::_find_custom_resource_format_loader(const String &path) {
14241418
for (int i = 0; i < loader_count; ++i) {
14251419
if (loader[i]->get_script_instance() && loader[i]->get_script_instance()->get_script()->get_path() == path) {
@@ -1551,32 +1545,12 @@ void ResourceLoader::initialize() {}
15511545

15521546
void ResourceLoader::finalize() {}
15531547

1554-
ResourceLoadErrorNotify ResourceLoader::err_notify = nullptr;
1555-
DependencyErrorNotify ResourceLoader::dep_err_notify = nullptr;
1556-
1557-
bool ResourceLoader::create_missing_resources_if_class_unavailable = false;
1558-
bool ResourceLoader::abort_on_missing_resource = true;
1559-
bool ResourceLoader::timestamp_on_load = false;
1560-
1561-
thread_local bool ResourceLoader::import_thread = false;
1562-
thread_local int ResourceLoader::load_nesting = 0;
15631548
thread_local Vector<String> ResourceLoader::load_paths_stack;
15641549
thread_local HashMap<int, HashMap<String, Ref<Resource>>> ResourceLoader::res_ref_overrides;
1565-
thread_local ResourceLoader::ThreadLoadTask *ResourceLoader::curr_load_task = nullptr;
15661550

15671551
SafeBinaryMutex<ResourceLoader::BINARY_MUTEX_TAG> &_get_res_loader_mutex() {
15681552
return ResourceLoader::thread_load_mutex;
15691553
}
15701554

15711555
template <>
15721556
thread_local SafeBinaryMutex<ResourceLoader::BINARY_MUTEX_TAG>::TLSData SafeBinaryMutex<ResourceLoader::BINARY_MUTEX_TAG>::tls_data(_get_res_loader_mutex());
1573-
SafeBinaryMutex<ResourceLoader::BINARY_MUTEX_TAG> ResourceLoader::thread_load_mutex;
1574-
HashMap<String, ResourceLoader::ThreadLoadTask> ResourceLoader::thread_load_tasks;
1575-
bool ResourceLoader::cleaning_tasks = false;
1576-
1577-
HashMap<String, ResourceLoader::LoadToken *> ResourceLoader::user_load_tokens;
1578-
1579-
SelfList<Resource>::List ResourceLoader::remapped_list;
1580-
HashMap<String, Vector<String>> ResourceLoader::translation_remaps;
1581-
1582-
ResourceLoaderImport ResourceLoader::import = nullptr;

core/io/resource_loader.h

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,26 @@ class ResourceLoader {
148148

149149
static Ref<Resource> _load_complete_inner(LoadToken &p_load_token, Error *r_error, MutexLock<SafeBinaryMutex<BINARY_MUTEX_TAG>> &p_thread_load_lock);
150150

151-
static Ref<ResourceFormatLoader> loader[MAX_LOADERS];
152-
static int loader_count;
153-
static bool timestamp_on_load;
154-
155-
static void *err_notify_ud;
156-
static ResourceLoadErrorNotify err_notify;
157-
static void *dep_err_notify_ud;
158-
static DependencyErrorNotify dep_err_notify;
159-
static bool abort_on_missing_resource;
160-
static bool create_missing_resources_if_class_unavailable;
161-
static HashMap<String, Vector<String>> translation_remaps;
151+
static inline Ref<ResourceFormatLoader> loader[MAX_LOADERS];
152+
static inline int loader_count = 0;
153+
static inline bool timestamp_on_load = false;
154+
155+
static inline ResourceLoadErrorNotify err_notify = nullptr;
156+
static inline DependencyErrorNotify dep_err_notify = nullptr;
157+
static inline bool abort_on_missing_resource = true;
158+
static inline bool create_missing_resources_if_class_unavailable = false;
159+
static inline HashMap<String, Vector<String>> translation_remaps;
162160

163161
static String _path_remap(const String &p_path, bool *r_translation_remapped = nullptr);
164162
friend class Resource;
165163

166-
static SelfList<Resource>::List remapped_list;
164+
static inline SelfList<Resource>::List remapped_list;
167165

168166
friend class ResourceFormatImporter;
169167

170168
static Ref<Resource> _load(const String &p_path, const String &p_original_path, const String &p_type_hint, ResourceFormatLoader::CacheMode p_cache_mode, Error *r_error, bool p_use_sub_threads, float *r_progress);
171169

172-
static ResourceLoadedCallback _loaded_callback;
170+
static inline ResourceLoadedCallback _loaded_callback = nullptr;
173171

174172
static Ref<ResourceFormatLoader> _find_custom_resource_format_loader(const String &path);
175173

@@ -203,19 +201,19 @@ class ResourceLoader {
203201

204202
static void _run_load_task(void *p_userdata);
205203

206-
static thread_local bool import_thread;
207-
static thread_local int load_nesting;
204+
static inline thread_local bool import_thread = false;
205+
static inline thread_local int load_nesting = 0;
208206
static thread_local HashMap<int, HashMap<String, Ref<Resource>>> res_ref_overrides; // Outermost key is nesting level.
209207
static thread_local Vector<String> load_paths_stack;
210-
static thread_local ThreadLoadTask *curr_load_task;
208+
static inline thread_local ThreadLoadTask *curr_load_task = nullptr;
211209

212-
static SafeBinaryMutex<BINARY_MUTEX_TAG> thread_load_mutex;
210+
static inline SafeBinaryMutex<BINARY_MUTEX_TAG> thread_load_mutex;
213211
friend SafeBinaryMutex<BINARY_MUTEX_TAG> &_get_res_loader_mutex();
214212

215-
static HashMap<String, ThreadLoadTask> thread_load_tasks;
216-
static bool cleaning_tasks;
213+
static inline HashMap<String, ThreadLoadTask> thread_load_tasks;
214+
static inline bool cleaning_tasks = false;
217215

218-
static HashMap<String, LoadToken *> user_load_tokens;
216+
static inline HashMap<String, LoadToken *> user_load_tokens;
219217

220218
static float _dependency_get_progress(const String &p_path);
221219

@@ -295,7 +293,7 @@ class ResourceLoader {
295293
static void clear_thread_load_tasks();
296294

297295
static void set_load_callback(ResourceLoadedCallback p_callback);
298-
static ResourceLoaderImport import;
296+
static inline ResourceLoaderImport import = nullptr;
299297

300298
static bool add_custom_resource_format_loader(const String &script_path);
301299
static void add_custom_loaders();

core/io/resource_saver.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@
3434
#include "core/io/resource_loader.h"
3535
#include "core/object/script_language.h"
3636

37-
Ref<ResourceFormatSaver> ResourceSaver::saver[MAX_SAVERS];
38-
39-
int ResourceSaver::saver_count = 0;
40-
bool ResourceSaver::timestamp_on_save = false;
41-
ResourceSavedCallback ResourceSaver::save_callback = nullptr;
42-
ResourceSaverGetResourceIDForPath ResourceSaver::save_get_id_for_path = nullptr;
43-
4437
Error ResourceFormatSaver::save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags) {
4538
Error err = ERR_METHOD_NOT_FOUND;
4639
GDVIRTUAL_CALL(_save, p_resource, p_path, p_flags, err);

core/io/resource_saver.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ class ResourceSaver {
6363
MAX_SAVERS = 64
6464
};
6565

66-
static Ref<ResourceFormatSaver> saver[MAX_SAVERS];
67-
static int saver_count;
68-
static bool timestamp_on_save;
69-
static ResourceSavedCallback save_callback;
70-
static ResourceSaverGetResourceIDForPath save_get_id_for_path;
66+
static inline Ref<ResourceFormatSaver> saver[MAX_SAVERS];
67+
static inline int saver_count = 0;
68+
static inline bool timestamp_on_save = false;
69+
static inline ResourceSavedCallback save_callback = nullptr;
70+
static inline ResourceSaverGetResourceIDForPath save_get_id_for_path = nullptr;
7171

7272
static Ref<ResourceFormatSaver> _find_custom_resource_format_saver(const String &path);
7373

core/io/resource_uid.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ void ResourceUID::clear() {
351351
unique_ids.clear();
352352
changed = false;
353353
}
354+
354355
void ResourceUID::_bind_methods() {
355356
ClassDB::bind_method(D_METHOD("id_to_text", "id"), &ResourceUID::id_to_text);
356357
ClassDB::bind_method(D_METHOD("text_to_id", "text_id"), &ResourceUID::text_to_id);
@@ -366,11 +367,12 @@ void ResourceUID::_bind_methods() {
366367

367368
BIND_CONSTANT(INVALID_ID)
368369
}
369-
ResourceUID *ResourceUID::singleton = nullptr;
370+
370371
ResourceUID::ResourceUID() {
371372
ERR_FAIL_COND(singleton != nullptr);
372373
singleton = this;
373374
}
375+
374376
ResourceUID::~ResourceUID() {
375377
if (crypto != nullptr) {
376378
memdelete((CryptoCore::RandomGenerator *)crypto);

core/io/resource_uid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ResourceUID : public Object {
5555
};
5656

5757
HashMap<ID, Cache> unique_ids; //unique IDs and utf8 paths (less memory used)
58-
static ResourceUID *singleton;
58+
static inline ResourceUID *singleton = nullptr;
5959

6060
uint32_t cache_entries = 0;
6161
bool changed = false;

core/math/quick_hull.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
#include "core/templates/hash_map.h"
3434
#include "core/templates/hash_set.h"
3535

36-
uint32_t QuickHull::debug_stop_after = 0xFFFFFFFF;
37-
3836
Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_mesh) {
3937
/* CREATE AABB VOLUME */
4038

core/math/quick_hull.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ class QuickHull {
8585
};
8686

8787
public:
88-
static uint32_t debug_stop_after;
88+
static inline uint32_t debug_stop_after = 0xFFFFFFFF;
8989
static Error build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_mesh);
9090
};

core/object/class_db.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ MethodDefinition D_METHODP(const char *p_name, const char *const **p_args, uint3
4949

5050
#endif
5151

52-
ClassDB::APIType ClassDB::current_api = API_CORE;
53-
HashMap<ClassDB::APIType, uint32_t> ClassDB::api_hashes_cache;
54-
5552
void ClassDB::set_current_api(APIType p_api) {
5653
DEV_ASSERT(!api_hashes_cache.has(p_api)); // This API type may not be suitable for caching of hash if it can change later.
5754
current_api = p_api;
@@ -61,13 +58,7 @@ ClassDB::APIType ClassDB::get_current_api() {
6158
return current_api;
6259
}
6360

64-
HashMap<StringName, ClassDB::ClassInfo> ClassDB::classes;
65-
HashMap<StringName, StringName> ClassDB::resource_base_extensions;
66-
HashMap<StringName, StringName> ClassDB::compat_classes;
67-
6861
#ifdef TOOLS_ENABLED
69-
HashMap<StringName, ObjectGDExtension> ClassDB::placeholder_extensions;
70-
7162
class PlaceholderExtensionInstance {
7263
StringName class_name;
7364
HashMap<StringName, Variant> properties;
@@ -2178,9 +2169,6 @@ void ClassDB::get_extensions_for_type(const StringName &p_class, List<String> *p
21782169
}
21792170
}
21802171

2181-
HashMap<StringName, HashMap<StringName, Variant>> ClassDB::default_values;
2182-
HashSet<StringName> ClassDB::default_values_cached;
2183-
21842172
Variant ClassDB::class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid) {
21852173
if (!default_values_cached.has(p_class)) {
21862174
if (!default_values.has(p_class)) {
@@ -2319,7 +2307,6 @@ void ClassDB::unregister_extension_class(const StringName &p_class, bool p_free_
23192307
#endif
23202308
}
23212309

2322-
HashMap<StringName, ClassDB::NativeStruct> ClassDB::native_structs;
23232310
void ClassDB::register_native_struct(const StringName &p_name, const String &p_code, uint64_t p_current_size) {
23242311
NativeStruct ns;
23252312
ns.ccode = p_code;
@@ -2374,9 +2361,6 @@ void ClassDB::cleanup() {
23742361
native_structs.clear();
23752362
}
23762363

2377-
// Array to use in optional parameters on methods and the DEFVAL_ARRAY macro.
2378-
Array ClassDB::default_array_arg = Array::create_read_only();
2379-
23802364
bool ClassDB::is_default_array_arg(const Array &p_array) {
23812365
return p_array.is_same_instance(default_array_arg);
23822366
}

core/object/class_db.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ class ClassDB {
178178
};
179179
};
180180

181-
static HashMap<StringName, ClassInfo> classes;
182-
static HashMap<StringName, StringName> resource_base_extensions;
183-
static HashMap<StringName, StringName> compat_classes;
181+
static inline HashMap<StringName, ClassInfo> classes;
182+
static inline HashMap<StringName, StringName> resource_base_extensions;
183+
static inline HashMap<StringName, StringName> compat_classes;
184184

185185
#ifdef TOOLS_ENABLED
186-
static HashMap<StringName, ObjectGDExtension> placeholder_extensions;
186+
static inline HashMap<StringName, ObjectGDExtension> placeholder_extensions;
187187
#endif
188188

189189
#ifdef DEBUG_METHODS_ENABLED
@@ -192,22 +192,23 @@ class ClassDB {
192192
static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_compatibility, const char *method_name, const Variant **p_defs, int p_defcount);
193193
#endif
194194

195-
static APIType current_api;
196-
static HashMap<APIType, uint32_t> api_hashes_cache;
195+
static inline APIType current_api = API_CORE;
196+
static inline HashMap<APIType, uint32_t> api_hashes_cache;
197197

198198
static void _add_class(const StringName &p_class, const StringName &p_inherits);
199199

200-
static HashMap<StringName, HashMap<StringName, Variant>> default_values;
201-
static HashSet<StringName> default_values_cached;
200+
static inline HashMap<StringName, HashMap<StringName, Variant>> default_values;
201+
static inline HashSet<StringName> default_values_cached;
202202

203203
// Native structs, used by binder
204204
struct NativeStruct {
205205
String ccode; // C code to create the native struct, fields separated by ; Arrays accepted (even containing other structs), also function pointers. All types must be Godot types.
206206
uint64_t struct_size; // local size of struct, for comparison
207207
};
208-
static HashMap<StringName, NativeStruct> native_structs;
208+
static inline HashMap<StringName, NativeStruct> native_structs;
209209

210-
static Array default_array_arg;
210+
// Array to use in optional parameters on methods and the DEFVAL_ARRAY macro.
211+
static inline Array default_array_arg = Array::create_read_only();
211212
static bool is_default_array_arg(const Array &p_array);
212213

213214
private:

core/object/message_queue.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,6 @@ CallQueue::~CallQueue() {
486486

487487
//////////////////////
488488

489-
CallQueue *MessageQueue::main_singleton = nullptr;
490-
thread_local CallQueue *MessageQueue::thread_singleton = nullptr;
491-
492489
void MessageQueue::set_thread_singleton_override(CallQueue *p_thread_singleton) {
493490
#ifdef DEV_ENABLED
494491
if (thread_singleton) {

core/object/message_queue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class CallQueue {
157157
};
158158

159159
class MessageQueue : public CallQueue {
160-
static CallQueue *main_singleton;
161-
static thread_local CallQueue *thread_singleton;
160+
static inline CallQueue *main_singleton = nullptr;
161+
static inline thread_local CallQueue *thread_singleton = nullptr;
162162
friend class CallQueue;
163163

164164
public:

core/object/object.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,12 +2391,6 @@ void Object::get_argument_options(const StringName &p_function, int p_idx, List<
23912391
}
23922392
#endif
23932393

2394-
SpinLock ObjectDB::spin_lock;
2395-
uint32_t ObjectDB::slot_count = 0;
2396-
uint32_t ObjectDB::slot_max = 0;
2397-
ObjectDB::ObjectSlot *ObjectDB::object_slots = nullptr;
2398-
uint64_t ObjectDB::validator_counter = 0;
2399-
24002394
int ObjectDB::get_object_count() {
24012395
return slot_count;
24022396
}

core/object/object.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,11 +1018,11 @@ class ObjectDB {
10181018
Object *object = nullptr;
10191019
};
10201020

1021-
static SpinLock spin_lock;
1022-
static uint32_t slot_count;
1023-
static uint32_t slot_max;
1024-
static ObjectSlot *object_slots;
1025-
static uint64_t validator_counter;
1021+
static inline SpinLock spin_lock;
1022+
static inline uint32_t slot_count = 0;
1023+
static inline uint32_t slot_max = 0;
1024+
static inline ObjectSlot *object_slots = nullptr;
1025+
static inline uint64_t validator_counter = 0;
10261026

10271027
friend class Object;
10281028
friend void unregister_core_types();

0 commit comments

Comments
 (0)