1Index: hash.c 2=================================================================== 3RCS file: /cvs/gnome/gnome-xml/hash.c,v 4retrieving revision 1.30 5diff -u -r1.30 hash.c 6--- hash.c 29 Oct 2003 11:18:37 -0000 1.30 7+++ hash.c 24 Feb 2004 17:18:42 -0000 8@@ -26,6 +26,7 @@ 9 #include <libxml/xmlmemory.h> 10 #include <libxml/xmlerror.h> 11 #include <libxml/globals.h> 12+#include <libxml/dict.h> 13 14 #define MAX_HASH_LEN 8 15 16@@ -38,9 +39,9 @@ 17 typedef xmlHashEntry *xmlHashEntryPtr; 18 struct _xmlHashEntry { 19 struct _xmlHashEntry *next; 20- xmlChar *name; 21- xmlChar *name2; 22- xmlChar *name3; 23+ const xmlChar *name; 24+ const xmlChar *name2; 25+ const xmlChar *name3; 26 void *payload; 27 int valid; 28 }; 29@@ -52,6 +53,7 @@ 30 struct _xmlHashEntry *table; 31 int size; 32 int nbElems; 33+ xmlDictPtr dict; 34 }; 35 36 /* 37@@ -143,12 +145,16 @@ 38 xmlHashTablePtr 39 xmlHashCreate(int size) { 40 xmlHashTablePtr table; 41+ xmlDictPtr dict; 42 43 if (size <= 0) 44 size = 256; 45 46+ dict = xmlDictCreate(); 47+ if (dict == NULL) return(NULL); 48 table = xmlMalloc(sizeof(xmlHashTable)); 49 if (table) { 50+ table->dict = dict; 51 table->size = size; 52 table->nbElems = 0; 53 table->table = xmlMalloc(size * sizeof(xmlHashEntry)); 54@@ -158,6 +164,7 @@ 55 } 56 xmlFree(table); 57 } 58+ xmlDictFree(dict); 59 return(NULL); 60 } 61 62@@ -282,12 +289,6 @@ 63 next = iter->next; 64 if ((f != NULL) && (iter->payload != NULL)) 65 f(iter->payload, iter->name); 66- if (iter->name) 67- xmlFree(iter->name); 68- if (iter->name2) 69- xmlFree(iter->name2); 70- if (iter->name3) 71- xmlFree(iter->name3); 72 iter->payload = NULL; 73 if (!inside_table) 74 xmlFree(iter); 75@@ -299,6 +300,7 @@ 76 } 77 xmlFree(table->table); 78 } 79+ xmlDictFree(table->dict); 80 xmlFree(table); 81 } 82 83@@ -465,6 +467,9 @@ 84 85 if ((table == NULL) || name == NULL) 86 return(-1); 87+ if (name) name = xmlDictLookup(table->dict, name, -1); 88+ if (name2) name2 = xmlDictLookup(table->dict, name2, -1); 89+ if (name3) name3 = xmlDictLookup(table->dict, name3, -1); 90 91 /* 92 * Check for duplicate and insertion location. 93@@ -475,15 +480,15 @@ 94 } else { 95 for (insert = &(table->table[key]); insert->next != NULL; 96 insert = insert->next) { 97- if ((xmlStrEqual(insert->name, name)) && 98- (xmlStrEqual(insert->name2, name2)) && 99- (xmlStrEqual(insert->name3, name3))) 100+ if ((insert->name == name) && 101+ (insert->name2 == name2) && 102+ (insert->name3 == name3)) 103 return(-1); 104 len++; 105 } 106- if ((xmlStrEqual(insert->name, name)) && 107- (xmlStrEqual(insert->name2, name2)) && 108- (xmlStrEqual(insert->name3, name3))) 109+ if ((insert->name == name) && 110+ (insert->name2 == name2) && 111+ (insert->name3 == name3)) 112 return(-1); 113 } 114 115@@ -495,9 +500,9 @@ 116 return(-1); 117 } 118 119- entry->name = xmlStrdup(name); 120- entry->name2 = xmlStrdup(name2); 121- entry->name3 = xmlStrdup(name3); 122+ entry->name = name; 123+ entry->name2 = name2; 124+ entry->name3 = name3; 125 entry->payload = userdata; 126 entry->next = NULL; 127 entry->valid = 1; 128@@ -539,6 +544,9 @@ 129 130 if ((table == NULL) || name == NULL) 131 return(-1); 132+ if (name) name = xmlDictLookup(table->dict, name, -1); 133+ if (name2) name2 = xmlDictLookup(table->dict, name2, -1); 134+ if (name3) name3 = xmlDictLookup(table->dict, name3, -1); 135 136 /* 137 * Check for duplicate and insertion location. 138@@ -549,18 +557,18 @@ 139 } else { 140 for (insert = &(table->table[key]); insert->next != NULL; 141 insert = insert->next) { 142- if ((xmlStrEqual(insert->name, name)) && 143- (xmlStrEqual(insert->name2, name2)) && 144- (xmlStrEqual(insert->name3, name3))) { 145+ if ((insert->name == name) && 146+ (insert->name2 == name2) && 147+ (insert->name3 == name3)) { 148 if (f) 149 f(insert->payload, insert->name); 150 insert->payload = userdata; 151 return(0); 152 } 153 } 154- if ((xmlStrEqual(insert->name, name)) && 155- (xmlStrEqual(insert->name2, name2)) && 156- (xmlStrEqual(insert->name3, name3))) { 157+ if ((insert->name == name) && 158+ (insert->name2 == name2) && 159+ (insert->name3 == name3)) { 160 if (f) 161 f(insert->payload, insert->name); 162 insert->payload = userdata; 163@@ -576,9 +584,9 @@ 164 return(-1); 165 } 166 167- entry->name = xmlStrdup(name); 168- entry->name2 = xmlStrdup(name2); 169- entry->name3 = xmlStrdup(name3); 170+ entry->name = name; 171+ entry->name2 = name2; 172+ entry->name3 = name3; 173 entry->payload = userdata; 174 entry->next = NULL; 175 entry->valid = 1; 176@@ -615,10 +623,13 @@ 177 key = xmlHashComputeKey(table, name, name2, name3); 178 if (table->table[key].valid == 0) 179 return(NULL); 180+ if (name) name = xmlDictLookup(table->dict, name, -1); 181+ if (name2) name2 = xmlDictLookup(table->dict, name2, -1); 182+ if (name3) name3 = xmlDictLookup(table->dict, name3, -1); 183 for (entry = &(table->table[key]); entry != NULL; entry = entry->next) { 184- if ((xmlStrEqual(entry->name, name)) && 185- (xmlStrEqual(entry->name2, name2)) && 186- (xmlStrEqual(entry->name3, name3))) 187+ if ((entry->name == name) && 188+ (entry->name2 == name2) && 189+ (entry->name3 == name3)) 190 return(entry->payload); 191 } 192 return(NULL); 193@@ -774,6 +785,9 @@ 194 if (f == NULL) 195 return; 196 197+ if (name) name = xmlDictLookup(table->dict, name, -1); 198+ if (name2) name2 = xmlDictLookup(table->dict, name2, -1); 199+ if (name3) name3 = xmlDictLookup(table->dict, name3, -1); 200 if (table->table) { 201 for(i = 0; i < table->size; i++) { 202 if (table->table[i].valid == 0) 203@@ -781,9 +795,9 @@ 204 iter = &(table->table[i]); 205 while (iter) { 206 next = iter->next; 207- if (((name == NULL) || (xmlStrEqual(name, iter->name))) && 208- ((name2 == NULL) || (xmlStrEqual(name2, iter->name2))) && 209- ((name3 == NULL) || (xmlStrEqual(name3, iter->name3))) && 210+ if (((name == NULL) || (name == iter->name)) && 211+ ((name2 == NULL) || (name2 == iter->name2)) && 212+ ((name3 == NULL) || (name3 == iter->name3)) && 213 (iter->payload != NULL)) { 214 f(iter->payload, data, iter->name, 215 iter->name2, iter->name3); 216@@ -913,19 +927,16 @@ 217 if (table->table[key].valid == 0) { 218 return(-1); 219 } else { 220+ if (name) name = xmlDictLookup(table->dict, name, -1); 221+ if (name2) name2 = xmlDictLookup(table->dict, name2, -1); 222+ if (name3) name3 = xmlDictLookup(table->dict, name3, -1); 223 for (entry = &(table->table[key]); entry != NULL; entry = entry->next) { 224- if (xmlStrEqual(entry->name, name) && 225- xmlStrEqual(entry->name2, name2) && 226- xmlStrEqual(entry->name3, name3)) { 227+ if ((entry->name == name) && 228+ (entry->name2 == name2) && 229+ (entry->name3 == name3)) { 230 if ((f != NULL) && (entry->payload != NULL)) 231 f(entry->payload, entry->name); 232 entry->payload = NULL; 233- if(entry->name) 234- xmlFree(entry->name); 235- if(entry->name2) 236- xmlFree(entry->name2); 237- if(entry->name3) 238- xmlFree(entry->name3); 239 if(prev) { 240 prev->next = entry->next; 241 xmlFree(entry); 242Index: include/libxml/hash.h 243=================================================================== 244RCS file: /cvs/gnome/gnome-xml/include/libxml/hash.h,v 245retrieving revision 1.15 246diff -u -r1.15 hash.h 247--- include/libxml/hash.h 20 Nov 2003 11:59:07 -0000 1.15 248+++ include/libxml/hash.h 24 Feb 2004 17:18:42 -0000 249@@ -42,7 +42,7 @@ 250 * 251 * Callback to free data from a hash. 252 */ 253-typedef void (*xmlHashDeallocator)(void *payload, xmlChar *name); 254+typedef void (*xmlHashDeallocator)(void *payload, const xmlChar *name); 255 /** 256 * xmlHashCopier: 257 * @payload: the data in the hash 258