|
34 | 34 | #include "core/string/string_builder.h" |
35 | 35 | #include "core/variant/variant_parser.h" |
36 | 36 |
|
37 | | -PackedStringArray ConfigFile::_get_sections() const { |
38 | | - List<String> s; |
39 | | - get_sections(&s); |
40 | | - PackedStringArray arr; |
41 | | - arr.resize(s.size()); |
42 | | - int idx = 0; |
43 | | - for (const String &E : s) { |
44 | | - arr.set(idx++, E); |
45 | | - } |
46 | | - |
47 | | - return arr; |
48 | | -} |
49 | | - |
50 | | -PackedStringArray ConfigFile::_get_section_keys(const String &p_section) const { |
51 | | - List<String> s; |
52 | | - get_section_keys(p_section, &s); |
53 | | - PackedStringArray arr; |
54 | | - arr.resize(s.size()); |
55 | | - int idx = 0; |
56 | | - for (const String &E : s) { |
57 | | - arr.set(idx++, E); |
58 | | - } |
59 | | - |
60 | | - return arr; |
61 | | -} |
62 | | - |
63 | 37 | void ConfigFile::set_value(const String &p_section, const String &p_key, const Variant &p_value) { |
64 | 38 | if (p_value.get_type() == Variant::NIL) { // Erase key. |
65 | 39 | if (!values.has(p_section)) { |
@@ -101,18 +75,33 @@ bool ConfigFile::has_section_key(const String &p_section, const String &p_key) c |
101 | 75 | return values[p_section].has(p_key); |
102 | 76 | } |
103 | 77 |
|
104 | | -void ConfigFile::get_sections(List<String> *r_sections) const { |
| 78 | +Vector<String> ConfigFile::get_sections() const { |
| 79 | + Vector<String> sections; |
| 80 | + sections.resize(values.size()); |
| 81 | + |
| 82 | + int i = 0; |
| 83 | + String *sections_write = sections.ptrw(); |
105 | 84 | for (const KeyValue<String, HashMap<String, Variant>> &E : values) { |
106 | | - r_sections->push_back(E.key); |
| 85 | + sections_write[i++] = E.key; |
107 | 86 | } |
| 87 | + |
| 88 | + return sections; |
108 | 89 | } |
109 | 90 |
|
110 | | -void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys) const { |
111 | | - ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot get keys from nonexistent section \"%s\".", p_section)); |
| 91 | +Vector<String> ConfigFile::get_section_keys(const String &p_section) const { |
| 92 | + Vector<String> keys; |
| 93 | + ERR_FAIL_COND_V_MSG(!values.has(p_section), keys, vformat("Cannot get keys from nonexistent section \"%s\".", p_section)); |
| 94 | + |
| 95 | + const HashMap<String, Variant> &keys_map = values[p_section]; |
| 96 | + keys.resize(keys_map.size()); |
112 | 97 |
|
113 | | - for (const KeyValue<String, Variant> &E : values[p_section]) { |
114 | | - r_keys->push_back(E.key); |
| 98 | + int i = 0; |
| 99 | + String *keys_write = keys.ptrw(); |
| 100 | + for (const KeyValue<String, Variant> &E : keys_map) { |
| 101 | + keys_write[i++] = E.key; |
115 | 102 | } |
| 103 | + |
| 104 | + return keys; |
116 | 105 | } |
117 | 106 |
|
118 | 107 | void ConfigFile::erase_section(const String &p_section) { |
@@ -325,8 +314,8 @@ void ConfigFile::_bind_methods() { |
325 | 314 | ClassDB::bind_method(D_METHOD("has_section", "section"), &ConfigFile::has_section); |
326 | 315 | ClassDB::bind_method(D_METHOD("has_section_key", "section", "key"), &ConfigFile::has_section_key); |
327 | 316 |
|
328 | | - ClassDB::bind_method(D_METHOD("get_sections"), &ConfigFile::_get_sections); |
329 | | - ClassDB::bind_method(D_METHOD("get_section_keys", "section"), &ConfigFile::_get_section_keys); |
| 317 | + ClassDB::bind_method(D_METHOD("get_sections"), &ConfigFile::get_sections); |
| 318 | + ClassDB::bind_method(D_METHOD("get_section_keys", "section"), &ConfigFile::get_section_keys); |
330 | 319 |
|
331 | 320 | ClassDB::bind_method(D_METHOD("erase_section", "section"), &ConfigFile::erase_section); |
332 | 321 | ClassDB::bind_method(D_METHOD("erase_section_key", "section", "key"), &ConfigFile::erase_section_key); |
|
0 commit comments