diff --git a/core/templates/list.h b/core/templates/list.h index 6393b942ff1..354e826a432 100644 --- a/core/templates/list.h +++ b/core/templates/list.h @@ -132,6 +132,8 @@ public: data->erase(this); } + void transfer_to_back(List *p_dst_list); + _FORCE_INLINE_ Element() {} }; @@ -762,4 +764,41 @@ public: } }; +template +void List::Element::transfer_to_back(List *p_dst_list) { + // Detach from current. + + if (data->first == this) { + data->first = data->first->next_ptr; + } + if (data->last == this) { + data->last = data->last->prev_ptr; + } + if (prev_ptr) { + prev_ptr->next_ptr = next_ptr; + } + if (next_ptr) { + next_ptr->prev_ptr = prev_ptr; + } + data->size_cache--; + + // Attach to the back of the new one. + + if (!p_dst_list->_data) { + p_dst_list->_data = memnew_allocator(_Data, A); + p_dst_list->_data->first = this; + p_dst_list->_data->last = nullptr; + p_dst_list->_data->size_cache = 0; + prev_ptr = nullptr; + } else { + p_dst_list->_data->last->next_ptr = this; + prev_ptr = p_dst_list->_data->last; + } + p_dst_list->_data->last = this; + next_ptr = nullptr; + + data = p_dst_list->_data; + p_dst_list->_data->size_cache++; +} + #endif // LIST_H diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index a2be6a86d73..05c25584177 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1391,36 +1391,54 @@ String GDScript::debug_get_script_name(const Ref