From 38d56c8351838fce3005ab92440c4c2320d92b0f Mon Sep 17 00:00:00 2001 From: Karroffel Date: Fri, 3 Nov 2017 14:33:19 +0100 Subject: [PATCH] make ConfigFile use OrderedHashMap --- core/io/config_file.cpp | 16 ++++++++-------- core/io/config_file.h | 3 ++- core/ordered_hash_map.h | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index daa6b01d6e9..b5d41bacbb2 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -75,7 +75,7 @@ void ConfigFile::set_value(const String &p_section, const String &p_key, const V } else { if (!values.has(p_section)) { - values[p_section] = Map(); + values[p_section] = OrderedHashMap(); } values[p_section][p_key] = p_value; @@ -106,7 +106,7 @@ bool ConfigFile::has_section_key(const String &p_section, const String &p_key) c void ConfigFile::get_sections(List *r_sections) const { - for (const Map >::Element *E = values.front(); E; E = E->next()) { + for (const Map >::Element *E = values.front(); E; E = E->next()) { r_sections->push_back(E->key()); } } @@ -114,8 +114,8 @@ void ConfigFile::get_section_keys(const String &p_section, List *r_keys) ERR_FAIL_COND(!values.has(p_section)); - for (const Map::Element *E = values[p_section].front(); E; E = E->next()) { - r_keys->push_back(E->key()); + for (OrderedHashMap::ConstElement E = values[p_section].front(); E; E = E.next()) { + r_keys->push_back(E.key()); } } @@ -135,17 +135,17 @@ Error ConfigFile::save(const String &p_path) { return err; } - for (Map >::Element *E = values.front(); E; E = E->next()) { + for (Map >::Element *E = values.front(); E; E = E->next()) { if (E != values.front()) file->store_string("\n"); file->store_string("[" + E->key() + "]\n\n"); - for (Map::Element *F = E->get().front(); F; F = F->next()) { + for (OrderedHashMap::Element F = E->get().front(); F; F = F.next()) { String vstr; - VariantWriter::write_to_string(F->get(), vstr); - file->store_string(F->key() + "=" + vstr + "\n"); + VariantWriter::write_to_string(F.get(), vstr); + file->store_string(F.key() + "=" + vstr + "\n"); } } diff --git a/core/io/config_file.h b/core/io/config_file.h index 8ed8a069e44..2be196faa25 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -30,13 +30,14 @@ #ifndef CONFIG_FILE_H #define CONFIG_FILE_H +#include "core/ordered_hash_map.h" #include "reference.h" class ConfigFile : public Reference { GDCLASS(ConfigFile, Reference); - Map > values; + Map > values; PoolStringArray _get_sections() const; PoolStringArray _get_section_keys(const String &p_section) const; diff --git a/core/ordered_hash_map.h b/core/ordered_hash_map.h index 9e95f963e13..62eeedb437d 100644 --- a/core/ordered_hash_map.h +++ b/core/ordered_hash_map.h @@ -181,7 +181,7 @@ public: }; ConstElement find(const K &p_key) const { - typename InternalList::Element **list_element = map.getptr(p_key); + typename InternalList::Element *const *list_element = map.getptr(p_key); if (list_element) { return ConstElement(*list_element); }