From a50c953854fe1793bc904cd9ee454ef9a80b9b98 Mon Sep 17 00:00:00 2001
From: Rubidium <rubidium@openttd.org>
Date: Sun, 12 Jan 2025 22:00:19 +0100
Subject: [PATCH] Codefix: Clone should make a clone, not copy some data to
 another instance

---
 src/newgrf.cpp         |  7 ++++---
 src/newgrf_commons.cpp | 10 ----------
 src/newgrf_commons.h   | 15 ---------------
 3 files changed, 4 insertions(+), 28 deletions(-)

diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index e1159468ae..88db46b315 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -2000,7 +2000,9 @@ static ChangeInfoResult StationChangeInfo(uint first, uint last, int prop, ByteR
 					if (buf.HasData(4) && buf.PeekDWord() == 0) {
 						buf.Skip(4);
 						extern const DrawTileSpriteSpan _station_display_datas_rail[8];
-						dts->Clone(&_station_display_datas_rail[t % 8]);
+						const DrawTileSpriteSpan &dtss = _station_display_datas_rail[t % 8];
+						dts->ground = dtss.ground;
+						dts->seq.insert(dts->seq.end(), dtss.GetSequence().begin(), dtss.GetSequence().end());
 						continue;
 					}
 
@@ -2050,8 +2052,7 @@ static ChangeInfoResult StationChangeInfo(uint first, uint last, int prop, ByteR
 				statspec->renderdata.reserve(srcstatspec->renderdata.size());
 
 				for (const auto &it : srcstatspec->renderdata) {
-					NewGRFSpriteLayout *dts = &statspec->renderdata.emplace_back();
-					dts->Clone(&it);
+					statspec->renderdata.emplace_back(it);
 				}
 				break;
 			}
diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp
index 5218e87e20..e0018b7243 100644
--- a/src/newgrf_commons.cpp
+++ b/src/newgrf_commons.cpp
@@ -566,16 +566,6 @@ bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t
 
 /* static */ std::vector<DrawTileSeqStruct> NewGRFSpriteLayout::result_seq;
 
-/**
- * Clone a spritelayout.
- * @param source The spritelayout to copy.
- */
-void NewGRFSpriteLayout::Clone(const NewGRFSpriteLayout *source)
-{
-	this->Clone((const DrawTileSprites*)source);
-	this->registers = source->registers;
-}
-
 
 /**
  * Allocate a spritelayout for \a num_sprites building sprites.
diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h
index b5c688728f..fc7d407796 100644
--- a/src/newgrf_commons.h
+++ b/src/newgrf_commons.h
@@ -121,21 +121,6 @@ struct NewGRFSpriteLayout : ZeroedMemoryAllocator, DrawTileSprites {
 
 	void Allocate(uint num_sprites);
 	void AllocateRegisters();
-	void Clone(const NewGRFSpriteLayout *source);
-
-	/**
-	 * Clone a spritelayout.
-	 * @param source The spritelayout to copy.
-	 */
-	void Clone(const DrawTileSprites *source)
-	{
-		assert(source != nullptr && this != source);
-
-		auto source_sequence = source->GetSequence();
-		assert(this->seq.empty() && !source_sequence.empty());
-		this->ground = source->ground;
-		this->seq.insert(this->seq.end(), source_sequence.begin(), source_sequence.end());
-	}
 
 	/**
 	 * Tests whether this spritelayout needs preprocessing by