Changeset - r24160:11d435e4f43a
[Not reviewed]
master
0 1 0
Michael Lutz - 4 years ago 2020-04-25 20:41:19
michi@icosahedron.de
Codechange: [Script] Improve copying a list into another empty list.
1 file changed with 11 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_list.cpp
Show inline comments
 
@@ -548,28 +548,35 @@ void ScriptList::Sort(SorterType sorter,
 

	
 
		default: NOT_REACHED();
 
	}
 
	this->sorter_type    = sorter;
 
	this->sort_ascending = ascending;
 
	this->initialized    = false;
 
}
 

	
 
void ScriptList::AddList(ScriptList *list)
 
{
 
	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);
 
		}
 
	}
 
}
 

	
 
void ScriptList::SwapList(ScriptList *list)
 
{
 
	if (list == this) return;
 

	
 
	this->items.swap(list->items);
 
	this->buckets.swap(list->buckets);
 
	Swap(this->sorter, list->sorter);
 
	Swap(this->sorter_type, list->sorter_type);
 
	Swap(this->sort_ascending, list->sort_ascending);
0 comments (0 inline, 0 general)