# HG changeset patch # User Michael Lutz # Date 2020-04-25 20:41:19 # Node ID 11d435e4f43ade5cc6c92a794c989569b9d9a714 # Parent ba10ed1bc03fe5ca9c88995bcfc7b5111fb1bca1 Codechange: [Script] Improve copying a list into another empty list. diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp --- a/src/script/api/script_list.cpp +++ b/src/script/api/script_list.cpp @@ -557,10 +557,17 @@ void ScriptList::AddList(ScriptList *lis { if (list == this) return; - ScriptListMap *list_items = &list->items; - for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) { - this->AddItem((*iter).first); - this->SetValue((*iter).first, (*iter).second); + if (this->IsEmpty()) { + /* If this is empty, we can just take the items of the other list as is. */ + this->items = list->items; + this->buckets = list->buckets; + this->modifications++; + } else { + ScriptListMap *list_items = &list->items; + for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) { + this->AddItem((*iter).first); + this->SetValue((*iter).first, (*iter).second); + } } }