Changeset 1902 in kBuild for trunk/src/kmk/variable.c
- Timestamp:
- Oct 21, 2008 3:57:00 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/variable.c
r1897 r1902 110 110 /* Hash table of all global variable definitions. */ 111 111 112 #ifndef CONFIG_WITH_STRCACHE2 112 113 static unsigned long 113 114 variable_hash_1 (const void *keyv) 114 115 { 115 116 struct variable const *key = (struct variable const *) keyv; 116 #ifndef CONFIG_WITH_STRCACHE2117 117 return_STRING_N_HASH_1 (key->name, key->length); 118 #else119 /* all requests are served from the cache. */120 return strcache2_get_ptr_hash (&variable_strcache, key->name);121 #endif122 118 } 123 119 … … 126 122 { 127 123 struct variable const *key = (struct variable const *) keyv; 128 #ifndef CONFIG_WITH_STRCACHE2129 124 return_STRING_N_HASH_2 (key->name, key->length); 130 #else131 /* all requests are served from the cache. */132 return strcache2_get_hash2 (&variable_strcache, key->name);133 #endif134 125 } 135 126 … … 139 130 struct variable const *x = (struct variable const *) xv; 140 131 struct variable const *y = (struct variable const *) yv; 141 #ifndef CONFIG_WITH_STRCACHE2142 132 int result = x->length - y->length; 143 133 if (result) … … 145 135 146 136 return_STRING_N_COMPARE (x->name, y->name, x->length); 147 #else /* CONFIG_WITH_STRCACHE2 */ 148 149 /* everything is in the cache. */ 150 return x->name == y->name ? 0 : -1; 151 #endif /* CONFIG_WITH_STRCACHE2 */ 152 } 137 } 138 #endif /* !CONFIG_WITH_STRCACHE2 */ 153 139 154 140 #ifndef VARIABLE_BUCKETS … … 185 171 init_hash_global_variable_set (void) 186 172 { 173 #ifndef CONFIG_WITH_STRCACHE2 187 174 hash_init (&global_variable_set.table, VARIABLE_BUCKETS, 188 175 variable_hash_1, variable_hash_2, variable_hash_cmp); 189 # ifdef CONFIG_WITH_STRCACHE2176 #else /* CONFIG_WITH_STRCACHE2 */ 190 177 strcache2_init (&variable_strcache, "variable", 65536, 0, 0, 0); 191 #endif 178 hash_init_strcached (&global_variable_set.table, VARIABLE_BUCKETS, 179 &variable_strcache, offsetof (struct variable, name)); 180 #endif /* CONFIG_WITH_STRCACHE2 */ 192 181 } 193 182 … … 236 225 || !(v = strcache2_get_user_val (&variable_strcache, var_key.name))) 237 226 { 238 var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);227 var_slot = (struct variable **) hash_find_slot_strcached (&set->table, &var_key); 239 228 v = *var_slot; 240 229 } … … 495 484 496 485 if (v == 0) 486 { 487 # ifndef NDEBUG 488 struct variable *v2 = (struct variable *) hash_find_item_strcached ((struct hash_table *) &setlist->set->table, &var_key); 489 assert (v2 == 0); 490 # endif 497 491 break; 492 } 498 493 if ((void *)v != hash_deleted_item) 499 494 { 500 if (v ariable_hash_cmp(&var_key, v) == 0)495 if (v->name == cached_name) 501 496 { 502 497 # ifndef NDEBUG 503 struct variable *v2 = (struct variable *) hash_find_item ((struct hash_table *) &setlist->set->table, &var_key);498 struct variable *v2 = (struct variable *) hash_find_item_strcached ((struct hash_table *) &setlist->set->table, &var_key); 504 499 assert (v2 == v); 505 500 # endif … … 509 504 } 510 505 if (!hash_2) 511 { 512 hash_2 = strcache2_get_hash2 (&variable_strcache, name); 513 assert (hash_2 & 1); 514 } 506 hash_2 = strcache2_get_hash1 (&variable_strcache, name) | 1; 515 507 hash_1 += hash_2; 516 508 } … … 520 512 struct variable *v; 521 513 514 # ifndef CONFIG_WITH_STRCACHE2 522 515 v = (struct variable *) hash_find_item ((struct hash_table *) &set->table, &var_key); 516 # else /* CONFIG_WITH_STRCACHE2 */ 517 v = (struct variable *) hash_find_item_strcached ((struct hash_table *) &set->table, &var_key); 518 # endif /* CONFIG_WITH_STRCACHE2 */ 523 519 if (v) 524 520 return v->special ? handle_special_var (v) : v; … … 596 592 { 597 593 struct variable var_key; 598 #ifdef CONFIG_WITH_STRCACHE2 594 #ifndef CONFIG_WITH_STRCACHE2 595 var_key.name = (char *) name; 596 var_key.length = length; 597 598 return (struct variable *) hash_find_item ((struct hash_table *) &set->table, &var_key); 599 #else /* CONFIG_WITH_STRCACHE2 */ 599 600 const char *cached_name; 600 601 … … 613 614 } 614 615 615 name = cached_name; 616 var_key.name = cached_name; 617 var_key.length = length; 618 619 return (struct variable *) hash_find_item_strcached ( 620 (struct hash_table *) &set->table, &var_key); 616 621 #endif /* CONFIG_WITH_STRCACHE2 */ 617 618 var_key.name = (char *) name;619 var_key.length = length;620 621 return (struct variable *) hash_find_item ((struct hash_table *) &set->table, &var_key);622 622 } 623 623 … … 643 643 xmalloc (sizeof (struct variable_set_list)); 644 644 l->set = xmalloc (sizeof (struct variable_set)); 645 #else 645 #else /* CONFIG_WITH_ALLOC_CACHES */ 646 646 l = (struct variable_set_list *) 647 647 alloccache_alloc (&variable_set_list_cache); 648 648 l->set = (struct variable_set *) 649 649 alloccache_alloc (&variable_set_cache); 650 #endif 650 #endif /* CONFIG_WITH_ALLOC_CACHES */ 651 #ifndef CONFIG_WITH_STRCACHE2 651 652 hash_init (&l->set->table, PERFILE_VARIABLE_BUCKETS, 652 653 variable_hash_1, variable_hash_2, variable_hash_cmp); 654 #else /* CONFIG_WITH_STRCACHE2 */ 655 hash_init_strcached (&l->set->table, PERFILE_VARIABLE_BUCKETS, 656 &variable_strcache, offsetof (struct variable, name)); 657 #endif /* CONFIG_WITH_STRCACHE2 */ 653 658 file->variables = l; 654 659 } … … 756 761 set = (struct variable_set *) alloccache_alloc (&variable_set_cache); 757 762 #endif 763 #ifndef CONFIG_WITH_STRCACHE2 758 764 hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS, 759 765 variable_hash_1, variable_hash_2, variable_hash_cmp); 766 #else /* CONFIG_WITH_STRCACHE2 */ 767 hash_init_strcached (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS, 768 &variable_strcache, offsetof (struct variable, name)); 769 #endif /* CONFIG_WITH_STRCACHE2 */ 760 770 761 771 #ifndef CONFIG_WITH_ALLOC_CACHES … … 878 888 struct variable *from_var = *from_var_slot; 879 889 struct variable **to_var_slot 890 #ifndef CONFIG_WITH_STRCACHE2 880 891 = (struct variable **) hash_find_slot (&to_set->table, *from_var_slot); 892 #else /* CONFIG_WITH_STRCACHE2 */ 893 = (struct variable **) hash_find_slot_strcached (&to_set->table, 894 *from_var_slot); 895 #endif /* CONFIG_WITH_STRCACHE2 */ 881 896 if (HASH_VACANT (*to_var_slot)) 882 897 hash_insert_at (&to_set->table, from_var, to_var_slot); … … 1296 1311 set_list = file->variables; 1297 1312 1313 #ifndef CONFIG_WITH_STRCACHE2 1298 1314 hash_init (&table, VARIABLE_BUCKETS, 1299 1315 variable_hash_1, variable_hash_2, variable_hash_cmp); 1316 #else /* CONFIG_WITH_STRCACHE2 */ 1317 hash_init_strcached (&table, VARIABLE_BUCKETS, 1318 &variable_strcache, offsetof (struct variable, name)); 1319 #endif /* CONFIG_WITH_STRCACHE2 */ 1300 1320 1301 1321 /* Run through all the variable sets in the list, … … 1368 1388 } 1369 1389 1390 #ifndef CONFIG_WITH_STRCACHE2 1370 1391 new_slot = (struct variable **) hash_find_slot (&table, v); 1392 #else /* CONFIG_WITH_STRCACHE2 */ 1393 new_slot = (struct variable **) hash_find_slot_strcached (&table, v); 1394 #endif /* CONFIG_WITH_STRCACHE2 */ 1371 1395 if (HASH_VACANT (*new_slot)) 1372 1396 hash_insert_at (&table, v, new_slot); … … 1381 1405 /* lookup the name in the string case, if it's not there it won't 1382 1406 be in any of the sets either. */ 1383 cached_name = strcache2_lookup (&variable_strcache,1384 MAKELEVEL_NAME, MAKELEVEL_LENGTH);1407 cached_name = strcache2_lookup (&variable_strcache, 1408 MAKELEVEL_NAME, MAKELEVEL_LENGTH); 1385 1409 if (cached_name) 1386 1410 { 1387 1411 makelevel_key.name = cached_name; 1388 1412 makelevel_key.length = MAKELEVEL_LENGTH; 1389 hash_delete (&table, &makelevel_key);1413 hash_delete_strcached (&table, &makelevel_key); 1390 1414 } 1391 1415 #endif /* CONFIG_WITH_STRCACHE2 */
Note:
See TracChangeset
for help on using the changeset viewer.