summaryrefslogtreecommitdiff
path: root/src/script/api
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2020-04-25 22:41:19 +0200
committerMichael Lutz <michi@icosahedron.de>2020-04-26 18:09:42 +0200
commit1f1345de098294a4744981d0043512569a35102a (patch)
treee0988709a55664d9243b6769df8ae417428d2023 /src/script/api
parente45bccb83347bd0b36ae0915b6874e440f1c9164 (diff)
downloadopenttd-1f1345de098294a4744981d0043512569a35102a.tar.xz
Codechange: [Script] Improve copying a list into another empty list.
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/script_list.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp
index 2fb2a8d6b..4d8b39ea1 100644
--- a/src/script/api/script_list.cpp
+++ b/src/script/api/script_list.cpp
@@ -557,10 +557,17 @@ 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);
+ }
}
}