Codechange: [Script] Improve copying a list into another empty list.

pull/175/head
Michael Lutz 4 years ago
parent e45bccb833
commit 1f1345de09

@ -557,12 +557,19 @@ void ScriptList::AddList(ScriptList *list)
{ {
if (list == this) return; if (list == this) return;
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; ScriptListMap *list_items = &list->items;
for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) { for (ScriptListMap::iterator iter = list_items->begin(); iter != list_items->end(); iter++) {
this->AddItem((*iter).first); this->AddItem((*iter).first);
this->SetValue((*iter).first, (*iter).second); this->SetValue((*iter).first, (*iter).second);
} }
} }
}
void ScriptList::SwapList(ScriptList *list) void ScriptList::SwapList(ScriptList *list)
{ {

Loading…
Cancel
Save