@@ -47,11 +47,8 @@ ecsact_async_error validate_merge_instructions(
47
47
return ECSACT_ASYNC_OK;
48
48
}
49
49
50
- auto components_range = std::ranges::views::all (components);
51
- auto entities = util::get_cpp_entities (components_range);
52
-
53
- auto other_components_range = std::ranges::views::all (other_components);
54
- auto other_entities = util::get_cpp_entities (other_components_range);
50
+ auto entities = util::get_cpp_entities (components);
51
+ auto other_entities = util::get_cpp_entities (other_components);
55
52
56
53
auto empty_view = std::ranges::empty_view<int >{};
57
54
@@ -63,23 +60,23 @@ ecsact_async_error validate_merge_instructions(
63
60
}
64
61
65
62
for (auto & component : components) {
66
- auto view = std::views::filter (
67
- other_components_range ,
68
- [&other_components_range ,
63
+ auto component_view = std::views::filter (
64
+ other_components ,
65
+ [&other_components ,
69
66
&component](types::cpp_execution_component other_component) {
70
67
return component._id == other_component._id ;
71
68
}
72
69
);
70
+
73
71
int same_component_count = 0 ;
74
72
int same_entity_count = 0 ;
75
- for (auto itr = view. begin (); itr != view. end (); itr++ ) {
73
+ for (auto & other_component : component_view ) {
76
74
same_component_count++;
77
- if (component.entity_id == itr-> entity_id ) {
75
+ if (component.entity_id == other_component. entity_id ) {
78
76
same_entity_count++;
79
77
}
80
78
if (same_component_count > 0 && same_entity_count > 0 ) {
81
79
return ECSACT_ASYNC_ERR_EXECUTION_MERGE_FAILURE;
82
- break ;
83
80
}
84
81
}
85
82
}
@@ -95,7 +92,7 @@ ecsact_execution_options util::cpp_to_c_execution_options(
95
92
96
93
if (options.actions .size () > 0 ) {
97
94
std::vector<ecsact_action> deserialized_actions;
98
- deserialized_actions.resize (options.actions .size ());
95
+ deserialized_actions.reserve (options.actions .size ());
99
96
for (auto & action_info : options.actions ) {
100
97
auto action =
101
98
ecsact::deserialize (action_info.action_id , action_info.serialized_data );
@@ -107,12 +104,13 @@ ecsact_execution_options util::cpp_to_c_execution_options(
107
104
c_options.actions_length = deserialized_actions.size ();
108
105
}
109
106
if (options.adds .size () > 0 ) {
110
- auto adds_range = std::ranges::views::all (options.adds );
111
- auto entities_view = util::get_cpp_entities (adds_range);
107
+ auto entities_view = util::get_cpp_entities (options.adds );
112
108
113
109
std::vector entities (entities_view.begin (), entities_view.end ());
114
110
115
111
std::vector<ecsact_component> component_list;
112
+ // NOTE: Don't resize and push back
113
+ component_list.reserve (options.adds .size ());
116
114
117
115
for (int i = 0 ; i < options.adds .size (); i++) {
118
116
auto & component_info = options.adds [i];
@@ -128,12 +126,12 @@ ecsact_execution_options util::cpp_to_c_execution_options(
128
126
c_options.add_components_length = options.adds .size ();
129
127
}
130
128
if (options.updates .size () > 0 ) {
131
- auto updates_range = std::ranges::views::all (options.updates );
132
- auto entities_view = util::get_cpp_entities (updates_range);
129
+ auto entities_view = util::get_cpp_entities (options.updates );
133
130
134
131
std::vector entities (entities_view.begin (), entities_view.end ());
135
132
136
133
std::vector<ecsact_component> component_list;
134
+ component_list.reserve (options.updates .size ());
137
135
138
136
for (int i = 0 ; i < options.updates .size (); i++) {
139
137
auto component_info = options.updates [i];
@@ -149,17 +147,16 @@ ecsact_execution_options util::cpp_to_c_execution_options(
149
147
c_options.add_components_length = options.updates .size ();
150
148
}
151
149
if (options.removes .size () > 0 ) {
152
- auto removes_range = std::ranges::views::all (options.removes );
153
-
154
- auto entities_view = util::get_cpp_entities (removes_range);
150
+ auto entities_view = util::get_cpp_entities (options.removes );
155
151
std::vector entities (entities_view.begin (), entities_view.end ());
156
152
157
- auto component_ids = util::get_cpp_component_ids (removes_range);
158
- std::vector<ecsact_component_id> component_list;
159
- component_list
160
- .insert (component_list.end (), component_ids.begin (), component_ids.end ());
153
+ auto component_ids_view = util::get_cpp_component_ids (options.removes );
154
+ std::vector component_ids (
155
+ component_ids_view.begin (),
156
+ component_ids_view.end ()
157
+ );
161
158
162
- c_options.remove_components = component_list .data ();
159
+ c_options.remove_components = component_ids .data ();
163
160
c_options.remove_components_entities = entities.data ();
164
161
c_options.remove_components_length = options.removes .size ();
165
162
}
@@ -170,6 +167,10 @@ types::cpp_execution_options util::c_to_cpp_execution_options(
170
167
const ecsact_execution_options options
171
168
) {
172
169
auto cpp_options = types::cpp_execution_options{};
170
+ cpp_options.adds .reserve (options.add_components_length );
171
+ cpp_options.updates .reserve (options.update_components_length );
172
+ cpp_options.removes .reserve (options.remove_components_length );
173
+ cpp_options.actions .reserve (options.actions_length );
173
174
174
175
if (options.add_components != nullptr ) {
175
176
for (int i = 0 ; i < options.add_components_length ; i++) {
0 commit comments