aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-04-22 01:25:41 +0200
committer GitHub <noreply@github.com>2024-04-22 01:25:41 +0200
commit34f161570fd7ca9381675be8a9ec3b9b409929e1 (patch)
treeedba52a563952d2cf14c6d8f2a4995ac8017c147 /extension/src/openvic-extension/classes/GFXPieChartTexture.hpp
parent00c03db2b10588081548b713a4272854a9051c1c (diff)
parent5192708bda86625a40ce67ff297dca8138f9cc13 (diff)
Merge pull request #218 from OpenVicProject/array-dict-tweaks
Pre-allocate and use std::move for Godot Arrays and Dictionaries
Diffstat (limited to 'extension/src/openvic-extension/classes/GFXPieChartTexture.hpp')
-rw-r--r--extension/src/openvic-extension/classes/GFXPieChartTexture.hpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp
index f1fbe1a..8683b10 100644
--- a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp
+++ b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp
@@ -54,12 +54,14 @@ namespace OpenVic {
return lhs.first < rhs.first;
});
godot_pie_chart_data_t array;
- for (auto const& [key, val] : sorted_dist) {
+ ERR_FAIL_COND_V(array.resize(sorted_dist.size()) != OK, {});
+ for (size_t idx = 0; idx < array.size(); ++idx) {
+ auto const& [key, val] = sorted_dist[idx];
Dictionary sub_dict;
sub_dict[_slice_identifier_key()] = Utilities::std_view_to_godot_string(key->get_identifier());
sub_dict[_slice_colour_key()] = Utilities::to_godot_color(key->get_colour());
sub_dict[_slice_weight_key()] = val.to_float();
- array.push_back(sub_dict);
+ array[idx] = std::move(sub_dict);
}
return array;
}