diff options
author | reduz <reduzio@gmail.com> | 2022-05-19 17:00:06 +0200 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2022-05-20 22:40:38 +0200 |
commit | 45af29da8095af16729955117a165d23e77cd740 (patch) | |
tree | 0436c59187702466a73d05caf9688a58e5935afd /core/io | |
parent | 410893ad0fb6f0d7d774b6529581d886defd6cf0 (diff) |
Add a new HashSet template
* Intended to replace RBSet in most cases.
* Optimized for iteration speed
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/file_access_pack.h | 4 | ||||
-rw-r--r-- | core/io/json.cpp | 4 | ||||
-rw-r--r-- | core/io/json.h | 2 | ||||
-rw-r--r-- | core/io/logger.cpp | 8 | ||||
-rw-r--r-- | core/io/resource.h | 2 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 2 | ||||
-rw-r--r-- | core/io/resource_format_binary.h | 2 | ||||
-rw-r--r-- | core/io/resource_importer.cpp | 4 | ||||
-rw-r--r-- | core/io/resource_loader.h | 2 |
9 files changed, 15 insertions, 15 deletions
diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index 404ad38c96..19a0cce796 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -34,9 +34,9 @@ #include "core/io/dir_access.h" #include "core/io/file_access.h" #include "core/string/print_string.h" +#include "core/templates/hash_set.h" #include "core/templates/list.h" #include "core/templates/rb_map.h" -#include "core/templates/rb_set.h" // Godot's packed file magic header ("GDPC" in ASCII). #define PACK_HEADER_MAGIC 0x43504447 @@ -73,7 +73,7 @@ private: PackedDir *parent = nullptr; String name; HashMap<String, PackedDir *> subdirs; - RBSet<String> files; + HashSet<String> files; }; struct PathMD5 { diff --git a/core/io/json.cpp b/core/io/json.cpp index b3a9762e75..4c4d91f851 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -55,7 +55,7 @@ String JSON::_make_indent(const String &p_indent, int p_size) { return indent_text; } -String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, RBSet<const void *> &p_markers, bool p_full_precision) { +String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, HashSet<const void *> &p_markers, bool p_full_precision) { String colon = ":"; String end_statement = ""; @@ -529,7 +529,7 @@ Error JSON::_parse_string(const String &p_json, Variant &r_ret, String &r_err_st } String JSON::stringify(const Variant &p_var, const String &p_indent, bool p_sort_keys, bool p_full_precision) { - RBSet<const void *> markers; + HashSet<const void *> markers; return _stringify(p_var, p_indent, 0, p_sort_keys, markers, p_full_precision); } diff --git a/core/io/json.h b/core/io/json.h index f883d3963a..6ba0a8c76b 100644 --- a/core/io/json.h +++ b/core/io/json.h @@ -70,7 +70,7 @@ class JSON : public RefCounted { static const char *tk_name[]; static String _make_indent(const String &p_indent, int p_size); - static String _stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, RBSet<const void *> &p_markers, bool p_full_precision = false); + static String _stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, HashSet<const void *> &p_markers, bool p_full_precision = false); static Error _get_token(const char32_t *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str); static Error _parse_value(Variant &value, Token &token, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str); static Error _parse_array(Array &array, const char32_t *p_str, int &index, int p_len, int &line, String &r_err_str); diff --git a/core/io/logger.cpp b/core/io/logger.cpp index 925bfdbd02..0418825009 100644 --- a/core/io/logger.cpp +++ b/core/io/logger.cpp @@ -128,7 +128,7 @@ void RotatedFileLogger::clear_old_backups() { da->list_dir_begin(); String f = da->get_next(); - RBSet<String> backups; + HashSet<String> backups; while (!f.is_empty()) { if (!da->current_is_dir() && f.begins_with(basename) && f.get_extension() == extension && f != base_path.get_file()) { backups.insert(f); @@ -137,12 +137,12 @@ void RotatedFileLogger::clear_old_backups() { } da->list_dir_end(); - if (backups.size() > max_backups) { + if (backups.size() > (uint32_t)max_backups) { // since backups are appended with timestamp and Set iterates them in sorted order, // first backups are the oldest int to_delete = backups.size() - max_backups; - for (RBSet<String>::Element *E = backups.front(); E && to_delete > 0; E = E->next(), --to_delete) { - da->remove(E->get()); + for (HashSet<String>::Iterator E = backups.begin(); E && to_delete > 0; ++E, --to_delete) { + da->remove(*E); } } } diff --git a/core/io/resource.h b/core/io/resource.h index 53c828f9cd..a45bc6e1e4 100644 --- a/core/io/resource.h +++ b/core/io/resource.h @@ -54,7 +54,7 @@ public: virtual String get_base_extension() const { return "res"; } private: - RBSet<ObjectID> owners; + HashSet<ObjectID> owners; friend class ResBase; friend class ResourceCache; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index cf87869a32..cb634632c8 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -2022,7 +2022,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref<Re // save internal resource table f->store_32(saved_resources.size()); //amount of internal resources Vector<uint64_t> ofs_pos; - RBSet<String> used_unique_ids; + HashSet<String> used_unique_ids; for (Ref<Resource> &r : saved_resources) { if (r->is_built_in()) { diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index db29909dd5..5da880ddb8 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -127,7 +127,7 @@ class ResourceFormatSaverBinaryInstance { bool big_endian; bool takeover_paths; String magic; - RBSet<Ref<Resource>> resource_set; + HashSet<Ref<Resource>> resource_set; struct NonPersistentKey { //for resource properties generated on the fly Ref<Resource> base; diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index 5deee9721b..934cb780e6 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -139,7 +139,7 @@ Ref<Resource> ResourceFormatImporter::load(const String &p_path, const String &p } void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extensions) const { - RBSet<String> found; + HashSet<String> found; for (int i = 0; i < importers.size(); i++) { List<String> local_exts; @@ -159,7 +159,7 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_ return; } - RBSet<String> found; + HashSet<String> found; for (int i = 0; i < importers.size(); i++) { String res_type = importers[i]->get_resource_type(); diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index e189ad1dff..815dd1dd72 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -145,7 +145,7 @@ private: bool start_next = true; int requests = 0; int poll_requests = 0; - RBSet<String> sub_tasks; + HashSet<String> sub_tasks; }; static void _thread_load_function(void *p_userdata); |