mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Dictionary::get_key_list use LocalVector instead of List.
This commit is contained in:
parent
4248411baf
commit
f7e4987d0e
13 changed files with 33 additions and 44 deletions
|
|
@ -122,8 +122,7 @@ String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_
|
||||||
ERR_FAIL_COND_V_MSG(p_markers.has(d.id()), "\"{...}\"", "Converting circular structure to JSON.");
|
ERR_FAIL_COND_V_MSG(p_markers.has(d.id()), "\"{...}\"", "Converting circular structure to JSON.");
|
||||||
p_markers.insert(d.id());
|
p_markers.insert(d.id());
|
||||||
|
|
||||||
List<Variant> keys;
|
LocalVector<Variant> keys = d.get_key_list();
|
||||||
d.get_key_list(&keys);
|
|
||||||
|
|
||||||
if (p_sort_keys) {
|
if (p_sort_keys) {
|
||||||
keys.sort_custom<StringLikeVariantOrder>();
|
keys.sort_custom<StringLikeVariantOrder>();
|
||||||
|
|
|
||||||
|
|
@ -272,9 +272,7 @@ void Resource::_dupe_sub_resources(Variant &r_variant, Node *p_for_scene, HashMa
|
||||||
} break;
|
} break;
|
||||||
case Variant::DICTIONARY: {
|
case Variant::DICTIONARY: {
|
||||||
Dictionary d = r_variant;
|
Dictionary d = r_variant;
|
||||||
List<Variant> keys;
|
for (Variant &k : d.get_key_list()) {
|
||||||
d.get_key_list(&keys);
|
|
||||||
for (Variant &k : keys) {
|
|
||||||
if (k.get_type() == Variant::OBJECT) {
|
if (k.get_type() == Variant::OBJECT) {
|
||||||
// Replace in dictionary key.
|
// Replace in dictionary key.
|
||||||
Ref<Resource> sr = k;
|
Ref<Resource> sr = k;
|
||||||
|
|
|
||||||
|
|
@ -57,14 +57,14 @@ Dictionary::ConstIterator Dictionary::end() const {
|
||||||
return _p->variant_map.end();
|
return _p->variant_map.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dictionary::get_key_list(List<Variant> *p_keys) const {
|
LocalVector<Variant> Dictionary::get_key_list() const {
|
||||||
if (_p->variant_map.is_empty()) {
|
LocalVector<Variant> keys;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
keys.reserve(_p->variant_map.size());
|
||||||
for (const KeyValue<Variant, Variant> &E : _p->variant_map) {
|
for (const KeyValue<Variant, Variant> &E : _p->variant_map) {
|
||||||
p_keys->push_back(E.key);
|
keys.push_back(E.key);
|
||||||
}
|
}
|
||||||
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant Dictionary::get_key_at_index(int p_index) const {
|
Variant Dictionary::get_key_at_index(int p_index) const {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
#include "core/string/ustring.h"
|
#include "core/string/ustring.h"
|
||||||
#include "core/templates/hash_map.h"
|
#include "core/templates/hash_map.h"
|
||||||
#include "core/templates/list.h"
|
#include "core/templates/local_vector.h"
|
||||||
#include "core/templates/pair.h"
|
#include "core/templates/pair.h"
|
||||||
#include "core/variant/array.h"
|
#include "core/variant/array.h"
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ public:
|
||||||
ConstIterator begin() const;
|
ConstIterator begin() const;
|
||||||
ConstIterator end() const;
|
ConstIterator end() const;
|
||||||
|
|
||||||
void get_key_list(List<Variant> *p_keys) const;
|
LocalVector<Variant> get_key_list() const;
|
||||||
Variant get_key_at_index(int p_index) const;
|
Variant get_key_at_index(int p_index) const;
|
||||||
Variant get_value_at_index(int p_index) const;
|
Variant get_value_at_index(int p_index) const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@
|
||||||
#include "core/os/keyboard.h"
|
#include "core/os/keyboard.h"
|
||||||
#include "core/string/node_path.h"
|
#include "core/string/node_path.h"
|
||||||
#include "core/string/ustring.h"
|
#include "core/string/ustring.h"
|
||||||
|
#include "core/templates/list.h"
|
||||||
#include "core/templates/paged_allocator.h"
|
#include "core/templates/paged_allocator.h"
|
||||||
#include "core/templates/rid.h"
|
#include "core/templates/rid.h"
|
||||||
#include "core/variant/array.h"
|
#include "core/variant/array.h"
|
||||||
|
|
|
||||||
|
|
@ -2248,8 +2248,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
||||||
ERR_PRINT("Max recursion reached");
|
ERR_PRINT("Max recursion reached");
|
||||||
p_store_string_func(p_store_string_ud, "{}");
|
p_store_string_func(p_store_string_ud, "{}");
|
||||||
} else {
|
} else {
|
||||||
List<Variant> keys;
|
LocalVector<Variant> keys = dict.get_key_list();
|
||||||
dict.get_key_list(&keys);
|
|
||||||
keys.sort_custom<StringLikeVariantOrder>();
|
keys.sort_custom<StringLikeVariantOrder>();
|
||||||
|
|
||||||
if (keys.is_empty()) {
|
if (keys.is_empty()) {
|
||||||
|
|
@ -2260,11 +2259,12 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
||||||
|
|
||||||
p_store_string_func(p_store_string_ud, "{\n");
|
p_store_string_func(p_store_string_ud, "{\n");
|
||||||
|
|
||||||
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
for (uint32_t i = 0; i < keys.size(); i++) {
|
||||||
write(E->get(), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count, p_compat);
|
const Variant &key = keys[i];
|
||||||
|
write(key, p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count, p_compat);
|
||||||
p_store_string_func(p_store_string_ud, ": ");
|
p_store_string_func(p_store_string_ud, ": ");
|
||||||
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);
|
write(dict[key], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count, p_compat);
|
||||||
if (E->next()) {
|
if (i + 1 < keys.size()) {
|
||||||
p_store_string_func(p_store_string_ud, ",\n");
|
p_store_string_func(p_store_string_ud, ",\n");
|
||||||
} else {
|
} else {
|
||||||
p_store_string_func(p_store_string_ud, "\n");
|
p_store_string_func(p_store_string_ud, "\n");
|
||||||
|
|
|
||||||
|
|
@ -3702,10 +3702,8 @@ void EditorNode::replace_resources_in_object(Object *p_object, const Vector<Ref<
|
||||||
} break;
|
} break;
|
||||||
case Variant::DICTIONARY: {
|
case Variant::DICTIONARY: {
|
||||||
Dictionary d = p_object->get(E.name);
|
Dictionary d = p_object->get(E.name);
|
||||||
List<Variant> keys;
|
|
||||||
bool dictionary_requires_updating = false;
|
bool dictionary_requires_updating = false;
|
||||||
d.get_key_list(&keys);
|
for (const Variant &F : d.get_key_list()) {
|
||||||
for (const Variant &F : keys) {
|
|
||||||
Variant v = d[F];
|
Variant v = d[F];
|
||||||
Ref<Resource> res = v;
|
Ref<Resource> res = v;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -638,9 +638,7 @@ EditorExportPlatform::ExportNotifier::~ExportNotifier() {
|
||||||
bool EditorExportPlatform::_export_customize_dictionary(Dictionary &dict, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins) {
|
bool EditorExportPlatform::_export_customize_dictionary(Dictionary &dict, LocalVector<Ref<EditorExportPlugin>> &customize_resources_plugins) {
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
List<Variant> keys;
|
for (const Variant &K : dict.get_key_list()) {
|
||||||
dict.get_key_list(&keys);
|
|
||||||
for (const Variant &K : keys) {
|
|
||||||
Variant v = dict[K];
|
Variant v = dict[K];
|
||||||
switch (v.get_type()) {
|
switch (v.get_type()) {
|
||||||
case Variant::OBJECT: {
|
case Variant::OBJECT: {
|
||||||
|
|
|
||||||
|
|
@ -1732,9 +1732,7 @@ void FileSystemDock::_folder_removed(const String &p_folder) {
|
||||||
|
|
||||||
// Remove assigned folder color for all subfolders.
|
// Remove assigned folder color for all subfolders.
|
||||||
bool folder_colors_updated = false;
|
bool folder_colors_updated = false;
|
||||||
List<Variant> paths;
|
for (const Variant &E : assigned_folder_colors.get_key_list()) {
|
||||||
assigned_folder_colors.get_key_list(&paths);
|
|
||||||
for (const Variant &E : paths) {
|
|
||||||
const String &path = E;
|
const String &path = E;
|
||||||
// These folder paths are guaranteed to end with a "/".
|
// These folder paths are guaranteed to end with a "/".
|
||||||
if (path.begins_with(p_folder)) {
|
if (path.begins_with(p_folder)) {
|
||||||
|
|
|
||||||
|
|
@ -2199,8 +2199,7 @@ void VisualShaderEditor::_update_nodes() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Variant> keys;
|
LocalVector<Variant> keys = added.get_key_list();
|
||||||
added.get_key_list(&keys);
|
|
||||||
keys.sort_custom<StringLikeVariantOrder>();
|
keys.sort_custom<StringLikeVariantOrder>();
|
||||||
|
|
||||||
for (const Variant &key : keys) {
|
for (const Variant &key : keys) {
|
||||||
|
|
|
||||||
|
|
@ -216,15 +216,15 @@ String GDScriptDocGen::_docvalue_from_variant(const Variant &p_variant, int p_re
|
||||||
} else {
|
} else {
|
||||||
result += "{";
|
result += "{";
|
||||||
|
|
||||||
List<Variant> keys;
|
LocalVector<Variant> keys = dict.get_key_list();
|
||||||
dict.get_key_list(&keys);
|
|
||||||
keys.sort_custom<StringLikeVariantOrder>();
|
keys.sort_custom<StringLikeVariantOrder>();
|
||||||
|
|
||||||
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
for (uint32_t i = 0; i < keys.size(); i++) {
|
||||||
if (E->prev()) {
|
const Variant &key = keys[i];
|
||||||
|
if (i > 0) {
|
||||||
result += ", ";
|
result += ", ";
|
||||||
}
|
}
|
||||||
result += _docvalue_from_variant(E->get(), p_recursion_level + 1) + ": " + _docvalue_from_variant(dict[E->get()], p_recursion_level + 1);
|
result += _docvalue_from_variant(key, p_recursion_level + 1) + ": " + _docvalue_from_variant(dict[key], p_recursion_level + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
result += "}";
|
result += "}";
|
||||||
|
|
|
||||||
|
|
@ -1317,8 +1317,7 @@ Error RenderingServer::mesh_create_surface_data_from_arrays(SurfaceData *r_surfa
|
||||||
}
|
}
|
||||||
Vector<SurfaceData::LOD> lods;
|
Vector<SurfaceData::LOD> lods;
|
||||||
if (index_array_len) {
|
if (index_array_len) {
|
||||||
List<Variant> keys;
|
LocalVector<Variant> keys = p_lods.get_key_list();
|
||||||
p_lods.get_key_list(&keys);
|
|
||||||
keys.sort(); // otherwise lod levels may get skipped
|
keys.sort(); // otherwise lod levels may get skipped
|
||||||
for (const Variant &E : keys) {
|
for (const Variant &E : keys) {
|
||||||
float distance = E;
|
float distance = E;
|
||||||
|
|
|
||||||
|
|
@ -115,19 +115,18 @@ TEST_CASE("[Dictionary] List init") {
|
||||||
CHECK_EQ(tdict[5.0], Variant(2.0));
|
CHECK_EQ(tdict[5.0], Variant(2.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("[Dictionary] get_key_lists()") {
|
TEST_CASE("[Dictionary] get_key_list()") {
|
||||||
Dictionary map;
|
Dictionary map;
|
||||||
List<Variant> keys;
|
LocalVector<Variant> keys;
|
||||||
List<Variant> *ptr = &keys;
|
keys = map.get_key_list();
|
||||||
map.get_key_list(ptr);
|
|
||||||
CHECK(keys.is_empty());
|
CHECK(keys.is_empty());
|
||||||
map[1] = 3;
|
map[1] = 3;
|
||||||
map.get_key_list(ptr);
|
keys = map.get_key_list();
|
||||||
CHECK(keys.size() == 1);
|
CHECK(keys.size() == 1);
|
||||||
CHECK(int(keys.front()->get()) == 1);
|
CHECK(int(keys[0]) == 1);
|
||||||
map[2] = 4;
|
map[2] = 4;
|
||||||
map.get_key_list(ptr);
|
keys = map.get_key_list();
|
||||||
CHECK(keys.size() == 3);
|
CHECK(keys.size() == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("[Dictionary] get_key_at_index()") {
|
TEST_CASE("[Dictionary] get_key_at_index()") {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue