Ignore:
Timestamp:
Oct 20, 2008, 1:50:58 AM (17 years ago)
Author:
bird
Message:

kmk: Save pointers to global variables together with the string in the string cache.

File:
1 edited

Legend:

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

    r1889 r1890  
    223223#ifndef CONFIG_WITH_STRCACHE2
    224224  var_key.name = (char *) name;
    225 #else
    226   var_key.name = name = strcache2_add (&variable_strcache, name, length);
    227 #endif
    228225  var_key.length = length;
    229226  var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
     
    233230
    234231  v = *var_slot;
     232#else  /* CONFIG_WITH_STRCACHE2 */
     233  var_key.name = name = strcache2_add (&variable_strcache, name, length);
     234  var_key.length = length;
     235  if (   set != &global_variable_set
     236      || !(v = strcache2_get_user_val (&variable_strcache, var_key.name)))
     237    {
     238      var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
     239      v = *var_slot;
     240    }
     241  else
     242    assert (!v || (v->name == name && !HASH_VACANT (v)));
     243#endif /* CONFIG_WITH_STRCACHE2 */
    235244  if (! HASH_VACANT (v))
    236245    {
     
    345354    }
    346355
     356#ifdef CONFIG_WITH_STRCACHE2
     357  /* If it's the global set, remember the variable. */
     358  if (set == &global_variable_set)
     359    strcache2_set_user_val (&variable_strcache, v->name, v);
     360#endif
    347361  return v;
    348362}
     
    465479  var_key.name = (char *) name;
    466480  var_key.length = length;
    467 #ifdef CONFIG_WITH_STRCACHE2
    468   var_key.value = (char *)&var_key; /* hack: name not cached */
    469 #endif
    470481
    471482  for (setlist = current_variable_set_list;
     
    589600
    590601  /* lookup the name in the string case, if it's not there it won't
    591      be in any of the sets either. */
     602     be in any of the sets either.  Optimize lookups in the global set. */
    592603  cached_name = strcache2_lookup(&variable_strcache, name, length);
    593604  if (!cached_name)
    594605    return NULL;
     606
     607  if (set == &global_variable_set)
     608    {
     609      struct variable *v;
     610      v = strcache2_get_user_val (&variable_strcache, cached_name);
     611      assert (!v || v->name == cached_name);
     612      return v;
     613    }
     614
    595615  name = cached_name;
    596616#endif /* CONFIG_WITH_STRCACHE2 */
     
    598618  var_key.name = (char *) name;
    599619  var_key.length = length;
    600 #ifdef CONFIG_WITH_STRCACHE2
    601   var_key.value = (char *)&var_key; /* hack: name not cached */
    602 #endif
    603620
    604621  return (struct variable *) hash_find_item ((struct hash_table *) &set->table, &var_key);
Note: See TracChangeset for help on using the changeset viewer.