Skip to content

Commit ec675fc

Browse files
committed
Merge pull request godotengine#100333 from YYF233333/reduce_list
Use `LocalVector` instead of `List` as arg of `Dictionary::get_key_list`
2 parents 4362b11 + f7e4987 commit ec675fc

File tree

13 files changed

+33
-44
lines changed

13 files changed

+33
-44
lines changed

core/io/json.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_
122122
ERR_FAIL_COND_V_MSG(p_markers.has(d.id()), "\"{...}\"", "Converting circular structure to JSON.");
123123
p_markers.insert(d.id());
124124

125-
List<Variant> keys;
126-
d.get_key_list(&keys);
125+
LocalVector<Variant> keys = d.get_key_list();
127126

128127
if (p_sort_keys) {
129128
keys.sort_custom<StringLikeVariantOrder>();

core/io/resource.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,7 @@ void Resource::_dupe_sub_resources(Variant &r_variant, Node *p_for_scene, HashMa
272272
} break;
273273
case Variant::DICTIONARY: {
274274
Dictionary d = r_variant;
275-
List<Variant> keys;
276-
d.get_key_list(&keys);
277-
for (Variant &k : keys) {
275+
for (Variant &k : d.get_key_list()) {
278276
if (k.get_type() == Variant::OBJECT) {
279277
// Replace in dictionary key.
280278
Ref<Resource> sr = k;

core/variant/dictionary.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ Dictionary::ConstIterator Dictionary::end() const {
5757
return _p->variant_map.end();
5858
}
5959

60-
void Dictionary::get_key_list(List<Variant> *p_keys) const {
61-
if (_p->variant_map.is_empty()) {
62-
return;
63-
}
60+
LocalVector<Variant> Dictionary::get_key_list() const {
61+
LocalVector<Variant> keys;
6462

63+
keys.reserve(_p->variant_map.size());
6564
for (const KeyValue<Variant, Variant> &E : _p->variant_map) {
66-
p_keys->push_back(E.key);
65+
keys.push_back(E.key);
6766
}
67+
return keys;
6868
}
6969

7070
Variant Dictionary::get_key_at_index(int p_index) const {

core/variant/dictionary.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
#include "core/string/ustring.h"
3434
#include "core/templates/hash_map.h"
35-
#include "core/templates/list.h"
35+
#include "core/templates/local_vector.h"
3636
#include "core/templates/pair.h"
3737
#include "core/variant/array.h"
3838

@@ -55,7 +55,7 @@ class Dictionary {
5555
ConstIterator begin() const;
5656
ConstIterator end() const;
5757

58-
void get_key_list(List<Variant> *p_keys) const;
58+
LocalVector<Variant> get_key_list() const;
5959
Variant get_key_at_index(int p_index) const;
6060
Variant get_value_at_index(int p_index) const;
6161

core/variant/variant.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "core/os/keyboard.h"
5555
#include "core/string/node_path.h"
5656
#include "core/string/ustring.h"
57+
#include "core/templates/list.h"
5758
#include "core/templates/paged_allocator.h"
5859
#include "core/templates/rid.h"
5960
#include "core/variant/array.h"

core/variant/variant_parser.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,8 +2248,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
22482248
ERR_PRINT("Max recursion reached");
22492249
p_store_string_func(p_store_string_ud, "{}");
22502250
} else {
2251-
List<Variant> keys;
2252-
dict.get_key_list(&keys);
2251+
LocalVector<Variant> keys = dict.get_key_list();
22532252
keys.sort_custom<StringLikeVariantOrder>();
22542253

22552254
if (keys.is_empty()) {
@@ -2260,11 +2259,12 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
22602259

22612260
p_store_string_func(p_store_string_ud, "{\n");
22622261

2263-
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
2264-
write(E->get(), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count, p_compat);
2262+
for (uint32_t i = 0; i < keys.size(); i++) {
2263+
const Variant &key = keys[i];
2264+
write(key, p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count, p_compat);
22652265
p_store_string_func(p_store_string_ud, ": ");
2266-
write(dict[E->get()], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count, p_compat);
2267-
if (E->next()) {
2266+
write(dict[key], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count, p_compat);
2267+
if (i + 1 < keys.size()) {
22682268
p_store_string_func(p_store_string_ud, ",\n");
22692269
} else {
22702270
p_store_string_func(p_store_string_ud, "\n");

editor/editor_node.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3702,10 +3702,8 @@ void EditorNode::replace_resources_in_object(Object *p_object, const Vector<Ref<
37023702
} break;
37033703
case Variant::DICTIONARY: {
37043704
Dictionary d = p_object->get(E.name);
3705-
List<Variant> keys;
37063705
bool dictionary_requires_updating = false;
3707-
d.get_key_list(&keys);
3708-
for (const Variant &F : keys) {
3706+
for (const Variant &F : d.get_key_list()) {
37093707
Variant v = d[F];
37103708
Ref<Resource> res = v;
37113709

editor/export/editor_export_platform.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,7 @@ EditorExportPlatform::ExportNotifier::~ExportNotifier() {
638638
bool EditorExportPlatform::_export_customize_dictionary(Dictionary &dict, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins) {
639639
bool changed = false;
640640

641-
List<Variant> keys;
642-
dict.get_key_list(&keys);
643-
for (const Variant &K : keys) {
641+
for (const Variant &K : dict.get_key_list()) {
644642
Variant v = dict[K];
645643
switch (v.get_type()) {
646644
case Variant::OBJECT: {

editor/filesystem_dock.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,9 +1732,7 @@ void FileSystemDock::_folder_removed(const String &p_folder) {
17321732

17331733
// Remove assigned folder color for all subfolders.
17341734
bool folder_colors_updated = false;
1735-
List<Variant> paths;
1736-
assigned_folder_colors.get_key_list(&paths);
1737-
for (const Variant &E : paths) {
1735+
for (const Variant &E : assigned_folder_colors.get_key_list()) {
17381736
const String &path = E;
17391737
// These folder paths are guaranteed to end with a "/".
17401738
if (path.begins_with(p_folder)) {

editor/plugins/visual_shader_editor_plugin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,8 +2199,7 @@ void VisualShaderEditor::_update_nodes() {
21992199
}
22002200
}
22012201

2202-
List<Variant> keys;
2203-
added.get_key_list(&keys);
2202+
LocalVector<Variant> keys = added.get_key_list();
22042203
keys.sort_custom<StringLikeVariantOrder>();
22052204

22062205
for (const Variant &key : keys) {

0 commit comments

Comments
 (0)