Skip to content

Commit

Permalink
Avoid const_cast in List::erase by requiring mutable elements
Browse files Browse the repository at this point in the history
  • Loading branch information
rune-scape committed Nov 8, 2024
1 parent b00e1cb commit a47daa0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions core/templates/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class List {
Element *last = nullptr;
int size_cache = 0;

bool erase(const Element *p_I) {
bool erase(Element *p_I) {
ERR_FAIL_NULL_V(p_I, false);
ERR_FAIL_COND_V(p_I->data != this, false);

Expand All @@ -244,7 +244,7 @@ class List {
p_I->next_ptr->prev_ptr = p_I->prev_ptr;
}

memdelete_allocator<Element, A>(const_cast<Element *>(p_I));
memdelete_allocator<Element, A>(p_I);
size_cache--;

return true;
Expand Down Expand Up @@ -430,7 +430,7 @@ class List {
/**
* erase an element in the list, by iterator pointing to it. Return true if it was found/erased.
*/
bool erase(const Element *p_I) {
bool erase(Element *p_I) {
if (_data && p_I) {
bool ret = _data->erase(p_I);

Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/visual_shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ void VisualShaderGraphPlugin::disconnect_nodes(VisualShader::Type p_type, int p_
if (visual_shader.is_valid() && visual_shader->get_shader_type() == p_type) {
graph->disconnect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);

for (const List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) {
for (List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) {
if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) {
connections.erase(E);
break;
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, con
void GraphEdit::disconnect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
ERR_FAIL_NULL_MSG(connections_layer, "connections_layer is missing.");

for (const List<Ref<Connection>>::Element *E = connections.front(); E; E = E->next()) {
for (List<Ref<Connection>>::Element *E = connections.front(); E; E = E->next()) {
if (E->get()->from_node == p_from && E->get()->from_port == p_from_port && E->get()->to_node == p_to && E->get()->to_port == p_to_port) {
connection_map[p_from].erase(E->get());
connection_map[p_to].erase(E->get());
Expand Down
2 changes: 1 addition & 1 deletion scene/resources/visual_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ void VisualShader::disconnect_nodes(Type p_type, int p_from_node, int p_from_por
ERR_FAIL_INDEX(p_type, TYPE_MAX);
Graph *g = &graph[p_type];

for (const List<Connection>::Element *E = g->connections.front(); E; E = E->next()) {
for (List<Connection>::Element *E = g->connections.front(); E; E = E->next()) {
if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) {
g->connections.erase(E);
g->nodes[p_from_node].next_connected_nodes.erase(p_to_node);
Expand Down

0 comments on commit a47daa0

Please sign in to comment.