Copy strings instead of merely storing ptrs to them

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2517 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2006-11-22 17:21:36 +00:00
parent 10b4db9d4e
commit ac82a58332
2 changed files with 6 additions and 6 deletions
+5 -5
View File
@@ -24,12 +24,12 @@
#include "alist.h" #include "alist.h"
alist_entry * alist_entry *
AlistEntry_New (const char *key, const char *value) AlistEntry_New (alist *m, const char *key, const char *value)
{ {
alist_entry *e; alist_entry *e;
e = malloc (sizeof(alist_entry)); e = malloc (sizeof(alist_entry));
e->key = key; e->key = StringBank_AddOrFindString(m->bank, key);
e->value = value; e->value = StringBank_AddOrFindString(m->bank, value);
e->next = NULL; e->next = NULL;
return e; return e;
} }
@@ -84,11 +84,11 @@ Alist_PutString (alist *m, const char *key, const char *value)
{ {
alist_entry *e = Alist_GetEntry (m, key); alist_entry *e = Alist_GetEntry (m, key);
if (e == NULL) { if (e == NULL) {
e = AlistEntry_New(key, value); e = AlistEntry_New(m, key, value);
e->next = m->first; e->next = m->first;
m->first = e; m->first = e;
} else { } else {
e->value = value; e->value = StringBank_AddOrFindString(m->bank, value);
} }
} }
+1 -1
View File
@@ -37,7 +37,7 @@ typedef struct _alist_map {
/* ***** alist_entry operations ***** */ /* ***** alist_entry operations ***** */
/* Constructor and destructor */ /* Constructor and destructor */
alist_entry *AlistEntry_New (const char *key, const char *value); alist_entry *AlistEntry_New (alist *m, const char *key, const char *value);
void AlistEntry_Free (alist_entry *e); void AlistEntry_Free (alist_entry *e);
/* ***** alist operations ***** */ /* ***** alist operations ***** */