VirtualBox

Changeset 1902 in kBuild for trunk/src/kmk/variable.c


Ignore:
Timestamp:
Oct 21, 2008 3:57:00 AM (16 years ago)
Author:
bird
Message:

kmk: Moved the strcache hash optimizations into the hash code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/variable.c

    r1897 r1902  
    110110/* Hash table of all global variable definitions.  */
    111111
     112#ifndef CONFIG_WITH_STRCACHE2
    112113static unsigned long
    113114variable_hash_1 (const void *keyv)
    114115{
    115116  struct variable const *key = (struct variable const *) keyv;
    116 #ifndef CONFIG_WITH_STRCACHE2
    117117  return_STRING_N_HASH_1 (key->name, key->length);
    118 #else
    119   /* all requests are served from the cache. */
    120   return strcache2_get_ptr_hash (&variable_strcache, key->name);
    121 #endif
    122118}
    123119
     
    126122{
    127123  struct variable const *key = (struct variable const *) keyv;
    128 #ifndef CONFIG_WITH_STRCACHE2
    129124  return_STRING_N_HASH_2 (key->name, key->length);
    130 #else
    131   /* all requests are served from the cache. */
    132   return strcache2_get_hash2 (&variable_strcache, key->name);
    133 #endif
    134125}
    135126
     
    139130  struct variable const *x = (struct variable const *) xv;
    140131  struct variable const *y = (struct variable const *) yv;
    141 #ifndef CONFIG_WITH_STRCACHE2
    142132  int result = x->length - y->length;
    143133  if (result)
     
    145135
    146136  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 */
    153139
    154140#ifndef VARIABLE_BUCKETS
     
    185171init_hash_global_variable_set (void)
    186172{
     173#ifndef CONFIG_WITH_STRCACHE2
    187174  hash_init (&global_variable_set.table, VARIABLE_BUCKETS,
    188175             variable_hash_1, variable_hash_2, variable_hash_cmp);
    189 #ifdef CONFIG_WITH_STRCACHE2
     176#else  /* CONFIG_WITH_STRCACHE2 */
    190177  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 */
    192181}
    193182
     
    236225      || !(v = strcache2_get_user_val (&variable_strcache, var_key.name)))
    237226    {
    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);
    239228      v = *var_slot;
    240229    }
     
    495484
    496485          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
    497491              break;
     492            }
    498493          if ((void *)v != hash_deleted_item)
    499494            {
    500               if (variable_hash_cmp(&var_key, v) == 0)
     495              if (v->name == cached_name)
    501496                {
    502497# 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);
    504499                  assert (v2 == v);
    505500# endif
     
    509504            }
    510505          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;
    515507          hash_1 += hash_2;
    516508        }
     
    520512      struct variable *v;
    521513
     514# ifndef CONFIG_WITH_STRCACHE2
    522515      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 */
    523519      if (v)
    524520        return v->special ? handle_special_var (v) : v;
     
    596592{
    597593  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 */
    599600  const char *cached_name;
    600601
     
    613614    }
    614615
    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);
    616621#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);
    622622}
    623623
     
    643643        xmalloc (sizeof (struct variable_set_list));
    644644      l->set = xmalloc (sizeof (struct variable_set));
    645 #else
     645#else  /* CONFIG_WITH_ALLOC_CACHES */
    646646      l = (struct variable_set_list *)
    647647        alloccache_alloc (&variable_set_list_cache);
    648648      l->set = (struct variable_set *)
    649649        alloccache_alloc (&variable_set_cache);
    650 #endif
     650#endif /* CONFIG_WITH_ALLOC_CACHES */
     651#ifndef CONFIG_WITH_STRCACHE2
    651652      hash_init (&l->set->table, PERFILE_VARIABLE_BUCKETS,
    652653                 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 */
    653658      file->variables = l;
    654659    }
     
    756761  set = (struct variable_set *) alloccache_alloc (&variable_set_cache);
    757762#endif
     763#ifndef CONFIG_WITH_STRCACHE2
    758764  hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS,
    759765             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 */
    760770
    761771#ifndef CONFIG_WITH_ALLOC_CACHES
     
    878888        struct variable *from_var = *from_var_slot;
    879889        struct variable **to_var_slot
     890#ifndef CONFIG_WITH_STRCACHE2
    880891          = (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 */
    881896        if (HASH_VACANT (*to_var_slot))
    882897          hash_insert_at (&to_set->table, from_var, to_var_slot);
     
    12961311    set_list = file->variables;
    12971312
     1313#ifndef CONFIG_WITH_STRCACHE2
    12981314  hash_init (&table, VARIABLE_BUCKETS,
    12991315             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 */
    13001320
    13011321  /* Run through all the variable sets in the list,
     
    13681388              }
    13691389
     1390#ifndef CONFIG_WITH_STRCACHE2
    13701391            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 */
    13711395            if (HASH_VACANT (*new_slot))
    13721396              hash_insert_at (&table, v, new_slot);
     
    13811405  /* lookup the name in the string case, if it's not there it won't
    13821406     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);
    13851409  if (cached_name)
    13861410    {
    13871411      makelevel_key.name = cached_name;
    13881412      makelevel_key.length = MAKELEVEL_LENGTH;
    1389       hash_delete (&table, &makelevel_key);
     1413      hash_delete_strcached (&table, &makelevel_key);
    13901414    }
    13911415#endif /* CONFIG_WITH_STRCACHE2 */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette