source:
vbox/trunk/src/libs/libxml2-2.9.14/optim/hash_dict.patch@
95629
最後變更 在這個檔案從95629是 95312,由 提交於 3 年 前 | |
---|---|
|
|
檔案大小: 7.6 KB |
-
hash.c
RCS file: /cvs/gnome/gnome-xml/hash.c,v retrieving revision 1.30 diff -u -r1.30 hash.c
26 26 #include <libxml/xmlmemory.h> 27 27 #include <libxml/xmlerror.h> 28 28 #include <libxml/globals.h> 29 #include <libxml/dict.h> 29 30 30 31 #define MAX_HASH_LEN 8 31 32 … … 38 39 typedef xmlHashEntry *xmlHashEntryPtr; 39 40 struct _xmlHashEntry { 40 41 struct _xmlHashEntry *next; 41 xmlChar *name;42 xmlChar *name2;43 xmlChar *name3;42 const xmlChar *name; 43 const xmlChar *name2; 44 const xmlChar *name3; 44 45 void *payload; 45 46 int valid; 46 47 }; … … 52 53 struct _xmlHashEntry *table; 53 54 int size; 54 55 int nbElems; 56 xmlDictPtr dict; 55 57 }; 56 58 57 59 /* … … 143 145 xmlHashTablePtr 144 146 xmlHashCreate(int size) { 145 147 xmlHashTablePtr table; 148 xmlDictPtr dict; 146 149 147 150 if (size <= 0) 148 151 size = 256; 149 152 153 dict = xmlDictCreate(); 154 if (dict == NULL) return(NULL); 150 155 table = xmlMalloc(sizeof(xmlHashTable)); 151 156 if (table) { 157 table->dict = dict; 152 158 table->size = size; 153 159 table->nbElems = 0; 154 160 table->table = xmlMalloc(size * sizeof(xmlHashEntry)); … … 158 164 } 159 165 xmlFree(table); 160 166 } 167 xmlDictFree(dict); 161 168 return(NULL); 162 169 } 163 170 … … 282 289 next = iter->next; 283 290 if ((f != NULL) && (iter->payload != NULL)) 284 291 f(iter->payload, iter->name); 285 if (iter->name)286 xmlFree(iter->name);287 if (iter->name2)288 xmlFree(iter->name2);289 if (iter->name3)290 xmlFree(iter->name3);291 292 iter->payload = NULL; 292 293 if (!inside_table) 293 294 xmlFree(iter); … … 299 300 } 300 301 xmlFree(table->table); 301 302 } 303 xmlDictFree(table->dict); 302 304 xmlFree(table); 303 305 } 304 306 … … 465 467 466 468 if ((table == NULL) || name == NULL) 467 469 return(-1); 470 if (name) name = xmlDictLookup(table->dict, name, -1); 471 if (name2) name2 = xmlDictLookup(table->dict, name2, -1); 472 if (name3) name3 = xmlDictLookup(table->dict, name3, -1); 468 473 469 474 /* 470 475 * Check for duplicate and insertion location. … … 475 480 } else { 476 481 for (insert = &(table->table[key]); insert->next != NULL; 477 482 insert = insert->next) { 478 if (( xmlStrEqual(insert->name, name)) &&479 ( xmlStrEqual(insert->name2, name2)) &&480 ( xmlStrEqual(insert->name3, name3)))483 if ((insert->name == name) && 484 (insert->name2 == name2) && 485 (insert->name3 == name3)) 481 486 return(-1); 482 487 len++; 483 488 } 484 if (( xmlStrEqual(insert->name, name)) &&485 ( xmlStrEqual(insert->name2, name2)) &&486 ( xmlStrEqual(insert->name3, name3)))489 if ((insert->name == name) && 490 (insert->name2 == name2) && 491 (insert->name3 == name3)) 487 492 return(-1); 488 493 } 489 494 … … 495 500 return(-1); 496 501 } 497 502 498 entry->name = xmlStrdup(name);499 entry->name2 = xmlStrdup(name2);500 entry->name3 = xmlStrdup(name3);503 entry->name = name; 504 entry->name2 = name2; 505 entry->name3 = name3; 501 506 entry->payload = userdata; 502 507 entry->next = NULL; 503 508 entry->valid = 1; … … 539 544 540 545 if ((table == NULL) || name == NULL) 541 546 return(-1); 547 if (name) name = xmlDictLookup(table->dict, name, -1); 548 if (name2) name2 = xmlDictLookup(table->dict, name2, -1); 549 if (name3) name3 = xmlDictLookup(table->dict, name3, -1); 542 550 543 551 /* 544 552 * Check for duplicate and insertion location. … … 549 557 } else { 550 558 for (insert = &(table->table[key]); insert->next != NULL; 551 559 insert = insert->next) { 552 if (( xmlStrEqual(insert->name, name)) &&553 ( xmlStrEqual(insert->name2, name2)) &&554 ( xmlStrEqual(insert->name3, name3))) {560 if ((insert->name == name) && 561 (insert->name2 == name2) && 562 (insert->name3 == name3)) { 555 563 if (f) 556 564 f(insert->payload, insert->name); 557 565 insert->payload = userdata; 558 566 return(0); 559 567 } 560 568 } 561 if (( xmlStrEqual(insert->name, name)) &&562 ( xmlStrEqual(insert->name2, name2)) &&563 ( xmlStrEqual(insert->name3, name3))) {569 if ((insert->name == name) && 570 (insert->name2 == name2) && 571 (insert->name3 == name3)) { 564 572 if (f) 565 573 f(insert->payload, insert->name); 566 574 insert->payload = userdata; … … 576 584 return(-1); 577 585 } 578 586 579 entry->name = xmlStrdup(name);580 entry->name2 = xmlStrdup(name2);581 entry->name3 = xmlStrdup(name3);587 entry->name = name; 588 entry->name2 = name2; 589 entry->name3 = name3; 582 590 entry->payload = userdata; 583 591 entry->next = NULL; 584 592 entry->valid = 1; … … 615 623 key = xmlHashComputeKey(table, name, name2, name3); 616 624 if (table->table[key].valid == 0) 617 625 return(NULL); 626 if (name) name = xmlDictLookup(table->dict, name, -1); 627 if (name2) name2 = xmlDictLookup(table->dict, name2, -1); 628 if (name3) name3 = xmlDictLookup(table->dict, name3, -1); 618 629 for (entry = &(table->table[key]); entry != NULL; entry = entry->next) { 619 if (( xmlStrEqual(entry->name, name)) &&620 ( xmlStrEqual(entry->name2, name2)) &&621 ( xmlStrEqual(entry->name3, name3)))630 if ((entry->name == name) && 631 (entry->name2 == name2) && 632 (entry->name3 == name3)) 622 633 return(entry->payload); 623 634 } 624 635 return(NULL); … … 774 785 if (f == NULL) 775 786 return; 776 787 788 if (name) name = xmlDictLookup(table->dict, name, -1); 789 if (name2) name2 = xmlDictLookup(table->dict, name2, -1); 790 if (name3) name3 = xmlDictLookup(table->dict, name3, -1); 777 791 if (table->table) { 778 792 for(i = 0; i < table->size; i++) { 779 793 if (table->table[i].valid == 0) … … 781 795 iter = &(table->table[i]); 782 796 while (iter) { 783 797 next = iter->next; 784 if (((name == NULL) || ( xmlStrEqual(name, iter->name))) &&785 ((name2 == NULL) || ( xmlStrEqual(name2, iter->name2))) &&786 ((name3 == NULL) || ( xmlStrEqual(name3, iter->name3))) &&798 if (((name == NULL) || (name == iter->name)) && 799 ((name2 == NULL) || (name2 == iter->name2)) && 800 ((name3 == NULL) || (name3 == iter->name3)) && 787 801 (iter->payload != NULL)) { 788 802 f(iter->payload, data, iter->name, 789 803 iter->name2, iter->name3); … … 913 927 if (table->table[key].valid == 0) { 914 928 return(-1); 915 929 } else { 930 if (name) name = xmlDictLookup(table->dict, name, -1); 931 if (name2) name2 = xmlDictLookup(table->dict, name2, -1); 932 if (name3) name3 = xmlDictLookup(table->dict, name3, -1); 916 933 for (entry = &(table->table[key]); entry != NULL; entry = entry->next) { 917 if ( xmlStrEqual(entry->name,name) &&918 xmlStrEqual(entry->name2,name2) &&919 xmlStrEqual(entry->name3,name3)) {934 if ((entry->name == name) && 935 (entry->name2 == name2) && 936 (entry->name3 == name3)) { 920 937 if ((f != NULL) && (entry->payload != NULL)) 921 938 f(entry->payload, entry->name); 922 939 entry->payload = NULL; 923 if(entry->name)924 xmlFree(entry->name);925 if(entry->name2)926 xmlFree(entry->name2);927 if(entry->name3)928 xmlFree(entry->name3);929 940 if(prev) { 930 941 prev->next = entry->next; 931 942 xmlFree(entry); -
include/libxml/hash.h
RCS file: /cvs/gnome/gnome-xml/include/libxml/hash.h,v retrieving revision 1.15 diff -u -r1.15 hash.h
42 42 * 43 43 * Callback to free data from a hash. 44 44 */ 45 typedef void (*xmlHashDeallocator)(void *payload, xmlChar *name);45 typedef void (*xmlHashDeallocator)(void *payload, const xmlChar *name); 46 46 /** 47 47 * xmlHashCopier: 48 48 * @payload: the data in the hash
注意:
瀏覽 TracBrowser
來幫助您使用儲存庫瀏覽器