changeset 6108:9cdb931d4e64 draft

(svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
author Darkvater <Darkvater@openttd.org>
date Thu, 22 Feb 2007 16:16:44 +0000
parents b46247236c4f
children e4401ec19b89
files src/newgrf_config.cpp src/newgrf_config.h src/oldloader.cpp
diffstat 3 files changed, 15 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -178,13 +178,13 @@
 }
 
 /** Appends an element to a list of GRFs
- * @param dst the head of the list to add to
- * @param el the element that is being added (as a copy) */
-void AppendToGRFConfigList(GRFConfig **dst, const GRFConfig *el)
+ * @param dst the head of the list to add to */
+void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el)
 {
 	GRFConfig **tail = dst;
 	while (*tail != NULL) tail = &(*tail)->next;
-	CopyGRFConfigList(tail, el);
+	*tail = el;
+
 	RemoveDuplicatesFromGRFConfigList(*dst);
 }
 
@@ -451,10 +451,9 @@
 
 static void Save_NGRF(void)
 {
-	GRFConfig *c;
 	int index = 0;
 
-	for (c = _grfconfig; c != NULL; c = c->next) {
+	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
 		if (HASBIT(c->flags, GCF_STATIC)) continue;
 		SlSetArrayIndex(index++);
 		SlObject(c, _grfconfig_desc);
@@ -464,12 +463,11 @@
 
 static void Load_NGRF(void)
 {
-	GRFConfig c;
-	memset(&c, 0, sizeof(GRFConfig));
-
+	ClearGRFConfigList(&_grfconfig);
 	while (SlIterateArray() != -1) {
-		SlObject(&c, _grfconfig_desc);
-		AppendToGRFConfigList(&_grfconfig, &c);
+		GRFConfig *c = CallocT<GRFConfig>(1);
+		SlObject(c, _grfconfig_desc);
+		AppendToGRFConfigList(&_grfconfig, c);
 	}
 
 	/* Append static NewGRF configuration */
--- a/src/newgrf_config.h
+++ b/src/newgrf_config.h
@@ -50,7 +50,7 @@
 GRFConfig *GetGRFConfig(uint32 grfid);
 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src);
 void AppendStaticGRFConfigs(GRFConfig **dst);
-void AppendToGRFConfigList(GRFConfig **dst, const GRFConfig *el);
+void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
 void ClearGRFConfig(GRFConfig **config);
 void ClearGRFConfigList(GRFConfig **config);
 void ResetGRFConfig(bool defaults);
--- a/src/oldloader.cpp
+++ b/src/oldloader.cpp
@@ -1367,18 +1367,16 @@
 				ReadUint32(ls); ReadByte(ls); len -= 5;
 
 				ClearGRFConfigList(&_grfconfig);
-				GRFConfig c;
-				memset(&c, 0, sizeof(GRFConfig));
-
 				while (len != 0) {
 					uint32 grfid = ReadUint32(ls);
 
 					if (ReadByte(ls) == 1) {
-						c.grfid = grfid;
-						c.filename = "TTDP game, no information";
+						GRFConfig *c = CallocT<GRFConfig>(1);
+						c->grfid = grfid;
+						c->filename = strdup("TTDP game, no information");
 
-						AppendToGRFConfigList(&_grfconfig, &c);
-						DEBUG(oldloader, 3, "TTDPatch game using GRF file with GRFID %0X", BSWAP32(c.grfid));
+						AppendToGRFConfigList(&_grfconfig, c);
+						DEBUG(oldloader, 3, "TTDPatch game using GRF file with GRFID %0X", BSWAP32(c->grfid));
 					}
 					len -= 5;
 				};