VirtualBox

Changeset 1902 in kBuild


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.

Location:
trunk/src/kmk
Files:
5 edited

Legend:

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

    r1901 r1902  
    377377  };
    378378
     379#ifndef CONFIG_WITH_STRCACHE2
    379380static unsigned long
    380381directory_hash_1 (const void *key)
    381382{
    382 #ifndef CONFIG_WITH_STRCACHE2
    383383  return_ISTRING_HASH_1 (((const struct directory *) key)->name);
    384 #else
    385   return strcache2_get_ptr_hash (&file_strcache, ((const struct directory *) key)->name);
    386 #endif
    387384}
    388385
     
    390387directory_hash_2 (const void *key)
    391388{
    392 #ifndef CONFIG_WITH_STRCACHE2
    393389  return_ISTRING_HASH_2 (((const struct directory *) key)->name);
    394 #else
    395   return strcache2_get_hash1 (&file_strcache, ((const struct directory *) key)->name);
    396 #endif
    397390}
    398391
     
    400393directory_hash_cmp (const void *x, const void *y)
    401394{
    402 #ifndef CONFIG_WITH_STRCACHE2
    403395  return_ISTRING_COMPARE (((const struct directory *) x)->name,
    404396                          ((const struct directory *) y)->name);
    405 #else
    406   return ((const struct directory *) x)->name
    407       == ((const struct directory *) y)->name ? 0 : -1;
    408 #endif
    409 }
     397}
     398#endif /* !CONFIG_WITH_STRCACHE2 */
    410399
    411400/* Table of directories hashed by name.  */
     
    433422  };
    434423
     424#ifndef CONFIG_WITH_STRCACHE2
    435425static unsigned long
    436426dirfile_hash_1 (const void *key)
    437427{
    438 #ifndef CONFIG_WITH_STRCACHE2
    439428  return_ISTRING_HASH_1 (((struct dirfile const *) key)->name);
    440 #else
    441   return strcache2_get_ptr_hash (&file_strcache, ((struct dirfile const *) key)->name);
    442 #endif
    443429}
    444430
     
    446432dirfile_hash_2 (const void *key)
    447433{
    448 #ifndef CONFIG_WITH_STRCACHE2
    449434  return_ISTRING_HASH_2 (((struct dirfile const *) key)->name);
    450 #else
    451   return strcache2_get_hash1 (&file_strcache, ((struct dirfile const *) key)->name);
    452 #endif
    453435}
    454436
     
    458440  const struct dirfile *x = xv;
    459441  const struct dirfile *y = yv;
    460 #ifndef CONFIG_WITH_STRCACHE2
    461442  int result = x->length - y->length;
    462443  if (result)
    463444    return result;
    464445  return_ISTRING_COMPARE (x->name, y->name);
    465 #else
    466   return x->name == y->name ? 0 : -1;
    467 #endif
    468 }
     446}
     447#endif /* !CONFIG_WITH_STRCACHE2 */
    469448
    470449#ifndef DIRFILE_BUCKETS
     
    510489#ifndef CONFIG_WITH_STRCACHE2
    511490  dir_key.name = name;
     491  dir_slot = (struct directory **) hash_find_slot (&directories, &dir_key);
    512492#else
    513493  p = name + strlen (name);
    514494  dir_key.name = strcache_add_len (name, p - name);
    515 #endif
    516   dir_slot = (struct directory **) hash_find_slot (&directories, &dir_key);
     495  dir_slot = (struct directory **) hash_find_slot_strcached (&directories, &dir_key);
     496#endif
    517497  dir = *dir_slot;
    518498
     
    657637                  if (buckets < DIRFILE_BUCKETS)
    658638                    buckets = DIRFILE_BUCKETS;
    659                   hash_init (&dc->dirfiles, buckets,
    660                              dirfile_hash_1, dirfile_hash_2, dirfile_hash_cmp);
    661 #else
     639                  hash_init_strcached (&dc->dirfiles, buckets, &file_strcache,
     640                                       offsetof (struct dirfile, name));
     641#else
     642# ifndef CONFIG_WITH_STRCACHE2
    662643                  hash_init (&dc->dirfiles, DIRFILE_BUCKETS,
    663644                             dirfile_hash_1, dirfile_hash_2, dirfile_hash_cmp);
     645# else  /* CONFIG_WITH_STRCACHE2 */
     646                  hash_init_strcached (&dc->dirfiles, DIRFILE_BUCKETS,
     647                                       &file_strcache,
     648                                       offsetof (struct dirfile, name));
     649# endif /* CONFIG_WITH_STRCACHE2 */
    664650#endif
    665651                  /* Keep track of how many directories are open.  */
     
    730716      dirfile_key.name = filename;
    731717      dirfile_key.length = strlen (filename);
     718      df = hash_find_item (&dir->dirfiles, &dirfile_key);
    732719#else  /* CONFIG_WITH_STRCACHE2 */
    733720      dirfile_key.length = strlen (filename);
    734721      dirfile_key.name = filename
    735722        = strcache_add_len (filename, dirfile_key.length);
     723      df = hash_find_item_strcached (&dir->dirfiles, &dirfile_key);
    736724#endif /* CONFIG_WITH_STRCACHE2 */
    737       df = hash_find_item (&dir->dirfiles, &dirfile_key);
    738725      if (df)
    739726        return !df->impossible;
     
    811798/* bird: end */
    812799          if (errno)
    813             fatal (NILF, "INTERNAL: readdir(%p): %s (filename=%s)\n", dir, strerror (errno), filename);
     800            fatal (NILF, "INTERNAL: readdir(%p): %s (filename=%s)\n", (void *)dir, strerror (errno), filename);
    814801          break;
    815802        }
     
    829816#ifndef CONFIG_WITH_STRCACHE2
    830817      dirfile_key.name = d->d_name;
    831 #else
    832       dirfile_key.name = strcache_add_len (d->d_name, len);
    833 #endif
    834818      dirfile_key.length = len;
    835819      dirfile_slot = (struct dirfile **) hash_find_slot (&dir->dirfiles, &dirfile_key);
     820#else
     821      dirfile_key.name = strcache_add_len (d->d_name, len);
     822      dirfile_key.length = len;
     823      dirfile_slot = (struct dirfile **) hash_find_slot_strcached (&dir->dirfiles, &dirfile_key);
     824#endif
    836825#ifdef WINDOWS32
    837826      /*
     
    10281017  if (dir->contents->dirfiles.ht_vec == 0)
    10291018    {
     1019#ifndef CONFIG_WITH_STRCACHE2
    10301020      hash_init (&dir->contents->dirfiles, DIRFILE_BUCKETS,
    10311021                 dirfile_hash_1, dirfile_hash_2, dirfile_hash_cmp);
     1022#else  /* CONFIG_WITH_STRCACHE2 */
     1023      hash_init_strcached (&dir->contents->dirfiles, DIRFILE_BUCKETS,
     1024                           &file_strcache, offsetof (struct dirfile, name));
     1025#endif /* CONFIG_WITH_STRCACHE2 */
    10321026    }
    10331027
     
    11221116  dirfile_key.name = filename;
    11231117  dirfile_key.length = strlen (filename);
     1118  dirfile = hash_find_item (&dir->dirfiles, &dirfile_key);
    11241119#else
    11251120  dirfile_key.length = strlen (filename);
    11261121  dirfile_key.name = strcache_add_len (filename, dirfile_key.length);
    1127 #endif
    1128   dirfile = hash_find_item (&dir->dirfiles, &dirfile_key);
     1122  dirfile = hash_find_item_strcached (&dir->dirfiles, &dirfile_key);
     1123#endif
    11291124  if (dirfile)
    11301125    return dirfile->impossible;
     
    13981393hash_init_directories (void)
    13991394{
     1395#ifndef CONFIG_WITH_STRCACHE2
    14001396  hash_init (&directories, DIRECTORY_BUCKETS,
    14011397             directory_hash_1, directory_hash_2, directory_hash_cmp);
     1398#else  /*  */
     1399  hash_init_strcached (&directories, DIRECTORY_BUCKETS, &file_strcache,
     1400                       offsetof (struct directory, name));
     1401#endif /*  */
    14021402  hash_init (&directory_contents, DIRECTORY_BUCKETS,
    14031403             directory_contents_hash_1, directory_contents_hash_2,
  • trunk/src/kmk/file.c

    r1901 r1902  
    4141/* Hash table of files the makefile knows how to make.  */
    4242
     43#ifndef CONFIG_WITH_STRCACHE2
    4344static unsigned long
    4445file_hash_1 (const void *key)
    4546{
    46 #ifndef CONFIG_WITH_STRCACHE2
    4747  return_ISTRING_HASH_1 (((struct file const *) key)->hname);
    48 #else  /* CONFIG_WITH_STRCACHE2 */
    49   return strcache2_get_ptr_hash (&file_strcache, ((struct file const *) key)->hname);
    50 #endif /* CONFIG_WITH_STRCACHE2 */
    5148}
    5249
     
    5451file_hash_2 (const void *key)
    5552{
    56 #ifndef CONFIG_WITH_STRCACHE2
    5753  return_ISTRING_HASH_2 (((struct file const *) key)->hname);
    58 #else  /* CONFIG_WITH_STRCACHE2 */
    59   return strcache2_get_ptr_hash (&file_strcache, ((struct file const *) key)->hname);
    60 #endif /* CONFIG_WITH_STRCACHE2 */
    61 }
     54}
     55#endif /* !CONFIG_WITH_STRCACHE2 */
    6256
    6357static int
     
    148142      file_key.hname = strcache2_lookup (&file_strcache, name, strlen (name));
    149143      if (file_key.hname)
    150         f = hash_find_item (&files, &file_key);
     144        f = hash_find_item_strcached (&files, &file_key);
    151145      else
    152146        f = NULL;
     
    155149    {
    156150      file_key.hname = name;
    157       f = hash_find_item (&files, &file_key);
     151      f = hash_find_item_strcached (&files, &file_key);
    158152    }
    159153
     
    296290
    297291  /* Remove the "from" file from the hash.  */
     292#ifndef CONFIG_WITH_STRCACHE2
    298293  deleted_file = hash_delete (&files, from_file);
     294#else
     295  deleted_file = hash_delete_strcached (&files, from_file);
     296#endif
    299297  if (deleted_file != from_file)
    300298    /* from_file isn't the one stored in files */
     
    13431341init_hash_files (void)
    13441342{
    1345 #ifdef KMK
     1343#ifndef CONFIG_WITH_STRCACHE2
     1344# ifdef KMK
    13461345  hash_init (&files, /*65535*/ 32755, file_hash_1, file_hash_2, file_hash_cmp);
     1346# else
     1347  hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp);
     1348# endif
    13471349#else
    1348   hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp);
     1350# ifdef KMK
     1351  hash_init_strcached (&files, 32755, &file_strcache,
     1352                       offsetof (struct file, hname));
     1353# else
     1354  hash_init_strcached (&files, 1000, &file_strcache,
     1355                       offsetof (struct file, hname));
     1356# endif
    13491357#endif
    13501358}
  • trunk/src/kmk/hash.c

    r1864 r1902  
    1919#include "make.h"
    2020#include "hash.h"
     21#ifdef CONFIG_WITH_STRCACHE2
     22# include <assert.h>
     23#endif
     24
    2125
    2226#define CALLOC(t, n) ((t *) calloc (sizeof (t), (n)))
     
    6266  ht->ht_hash_2 = hash_2;
    6367  ht->ht_compare = hash_cmp;
    64 }
     68#ifdef CONFIG_WITH_STRCACHE2
     69  ht->ht_strcache = 0;
     70  ht->ht_off_string = 0;
     71#endif
     72}
     73
     74#ifdef CONFIG_WITH_STRCACHE2
     75/* Same as hash_init, except that no callbacks are needed since all
     76   keys - including the ones being searched for - are from a string
     77   cache.  This means that any give string will only have one pointer
     78   value and that the hash and length can be retrived very cheaply,
     79   thus permitting some nice optimizations.
     80
     81   STRCACHE points to the string cache, while OFF_STRING gives the
     82   offset of the string pointer in the item structures the hash table
     83   entries points to.  */
     84void hash_init_strcached (struct hash_table *ht, unsigned long size,
     85                          struct strcache2 *strcache, unsigned int off_string)
     86{
     87  hash_init (ht, size, 0, 0, 0);
     88  ht->ht_strcache = strcache;
     89  ht->ht_off_string = off_string;
     90}
     91#endif /* CONFIG_WITH_STRCACHE2 */
    6592
    6693/* Load an array of items into `ht'.  */
     
    7198{
    7299  char *items = (char *) item_table;
     100#ifndef CONFIG_WITH_STRCACHE2
    73101  while (cardinality--)
    74102    {
     
    76104      items += size;
    77105    }
     106#else  /* CONFIG_WITH_STRCACHE2 */
     107  if (ht->ht_strcache)
     108    while (cardinality--)
     109      {
     110        hash_insert_strcached (ht, items);
     111        items += size;
     112      }
     113  else
     114    while (cardinality--)
     115      {
     116        hash_insert (ht, items);
     117        items += size;
     118      }
     119#endif /* CONFIG_WITH_STRCACHE2 */
    78120}
    79121
     
    90132  unsigned int hash_2 = 0;
    91133  unsigned int hash_1 = (*ht->ht_hash_1) (key);
     134
     135#ifdef CONFIG_WITH_STRCACHE2
     136  assert (ht->ht_strcache == 0);
     137#endif
    92138
    93139  ht->ht_lookups++;
     
    124170}
    125171
    126 #ifdef CONFIG_WITH_VALUE_LENGTH
    127 /* A variant of hash_find_slot that takes the hash values as arguments.
    128    The HASH_2 argument is optional, pass 0 if not available.
    129    Not having to call ht_hash_1 and perhaps also not ht_hash_2 does save
    130    a whole bunch of cycles in some of the kBuild use cases (strcache sees
    131    serious usage there). */
     172#ifdef CONFIG_WITH_STRCACHE2
     173/* hash_find_slot version for tables created with hash_init_strcached.  */
    132174void **
    133 hash_find_slot_prehashed (struct hash_table *ht, const void *key,
    134                           unsigned int hash_1, unsigned int hash_2)
     175hash_find_slot_strcached (struct hash_table *ht, const void *key)
    135176{
    136177  void **slot;
    137178  void **deleted_slot = 0;
     179  const char *str1 = *(const char **)((const char *)key + ht->ht_off_string);
     180  const char *str2;
     181  unsigned int hash_1 = strcache2_get_ptr_hash (ht->ht_strcache, str1);
     182  unsigned int hash_2;
     183
     184#ifdef CONFIG_WITH_STRCACHE2
     185  assert (ht->ht_strcache != 0);
     186#endif
    138187
    139188  ht->ht_lookups++;
     
    141190  make_stats_ht_lookups++;
    142191#endif
     192
     193  /* first iteration unrolled. */
     194
     195  hash_1 &= (ht->ht_size - 1);
     196  slot = &ht->ht_vec[hash_1];
     197  if (*slot == 0)
     198    return slot;
     199  if (*slot != hash_deleted_item)
     200    {
     201      str2 = *(const char **)((const char *)(*slot) + ht->ht_off_string);
     202      if (str1 == str2)
     203        return slot;
     204
     205      ht->ht_collisions++;
     206#ifdef CONFIG_WITH_MAKE_STATS
     207      make_stats_ht_collisions++;
     208#endif
     209    }
     210  else
     211    deleted_slot = slot;
     212
     213  /* the rest of the loop. */
     214
     215  hash_2 = strcache2_get_hash1 (ht->ht_strcache, str1) | 1;
     216  hash_1 += hash_2;
    143217  for (;;)
    144218    {
     
    155229      else
    156230        {
    157           if (key == *slot)
     231          str2 = *(const char **)((const char *)(*slot) + ht->ht_off_string);
     232          if (str1 == str2)
    158233            return slot;
    159           if ((*ht->ht_compare) (key, *slot) == 0)
    160             return slot;
     234
    161235          ht->ht_collisions++;
    162236#ifdef CONFIG_WITH_MAKE_STATS
     
    164238#endif
    165239        }
    166       if (!hash_2)
    167           hash_2 = (*ht->ht_hash_2) (key) | 1;
     240
    168241      hash_1 += hash_2;
    169242    }
    170243}
    171 
    172 #endif /* CONFIG_WITH_VALUE_LENGTH */
     244#endif /* CONFIG_WITH_STRCACHE2 */
    173245
    174246void *
     
    178250  return ((HASH_VACANT (*slot)) ? 0 : *slot);
    179251}
     252
     253#ifdef CONFIG_WITH_STRCACHE2
     254void *
     255hash_find_item_strcached (struct hash_table *ht, const void *key)
     256{
     257  void **slot = hash_find_slot_strcached (ht, key);
     258  return ((HASH_VACANT (*slot)) ? 0 : *slot);
     259}
     260#endif /* CONFIG_WITH_STRCACHE2 */
    180261
    181262void *
     
    188269}
    189270
     271#ifdef CONFIG_WITH_STRCACHE2
     272void *
     273hash_insert_strcached (struct hash_table *ht, const void *item)
     274{
     275  void **slot = hash_find_slot_strcached (ht, item);
     276  const void *old_item = slot ? *slot : 0;
     277  hash_insert_at (ht, item, slot);
     278  return (void *)((HASH_VACANT (old_item)) ? 0 : old_item);
     279}
     280#endif /* CONFIG_WITH_STRCACHE2 */
     281
    190282void *
    191283hash_insert_at (struct hash_table *ht, const void *item, const void *slot)
     
    203295    {
    204296      hash_rehash (ht);
     297#ifdef CONFIG_WITH_STRCACHE2
     298      if (ht->ht_strcache)
     299        return (void *)hash_find_slot_strcached (ht, item);
     300#endif /* CONFIG_WITH_STRCACHE2 */
    205301      return (void *) hash_find_slot (ht, item);
    206302    }
     
    215311  return hash_delete_at (ht, slot);
    216312}
     313
     314#ifdef CONFIG_WITH_STRCACHE2
     315void *
     316hash_delete_strcached (struct hash_table *ht, const void *item)
     317{
     318  void **slot = hash_find_slot_strcached (ht, item);
     319  return hash_delete_at (ht, slot);
     320}
     321#endif /* CONFIG_WITH_STRCACHE2 */
    217322
    218323void *
     
    353458  ht->ht_vec = (void **) CALLOC (struct token *, ht->ht_size);
    354459
     460#ifndef CONFIG_WITH_STRCACHE2
    355461  for (ovp = old_vec; ovp < &old_vec[old_ht_size]; ovp++)
    356462    {
     
    361467        }
    362468    }
     469#else  /* CONFIG_WITH_STRCACHE2 */
     470  if (ht->ht_strcache)
     471    for (ovp = old_vec; ovp < &old_vec[old_ht_size]; ovp++)
     472      {
     473        if (! HASH_VACANT (*ovp))
     474          {
     475            void **slot = hash_find_slot_strcached (ht, *ovp);
     476            *slot = *ovp;
     477          }
     478      }
     479  else
     480    for (ovp = old_vec; ovp < &old_vec[old_ht_size]; ovp++)
     481      {
     482        if (! HASH_VACANT (*ovp))
     483          {
     484            void **slot = hash_find_slot (ht, *ovp);
     485            *slot = *ovp;
     486          }
     487      }
     488#endif /* CONFIG_WITH_STRCACHE2 */
    363489  ht->ht_empty_slots = ht->ht_size - ht->ht_fill;
    364490  free (old_vec);
  • trunk/src/kmk/hash.h

    r1864 r1902  
    5454  hash_func_t ht_hash_2;        /* secondary hash function */
    5555  hash_cmp_func_t ht_compare;   /* comparison function */
     56#ifdef CONFIG_WITH_STRCACHE2
     57  struct strcache2 *ht_strcache; /* the string cache pointer. */
     58  unsigned int ht_off_string;  /* offsetof (struct key, string) */
     59#endif
    5660};
    5761
     
    6367                    unsigned long cardinality, unsigned long size));
    6468void **hash_find_slot __P((struct hash_table *ht, void const *key));
    65 #ifdef CONFIG_WITH_VALUE_LENGTH
    66 void **hash_find_slot_prehashed __P((struct hash_table *ht, const void *key,
    67                                      unsigned int hash_1, unsigned int hash_2));
    68 #endif
    6969void *hash_find_item __P((struct hash_table *ht, void const *key));
    7070void *hash_insert __P((struct hash_table *ht, const void *item));
     
    8484void **hash_dump __P((struct hash_table *ht, void **vector_0, qsort_cmp_t compare));
    8585
     86#ifdef CONFIG_WITH_STRCACHE2
     87void hash_init_strcached __P((struct hash_table *ht, unsigned long size,
     88                              struct strcache2 *strcache, unsigned int off_strptr));
     89void **hash_find_slot_strcached __P((struct hash_table *ht, const void *key));
     90void *hash_find_item_strcached __P((struct hash_table *ht, void const *key));
     91void *hash_insert_strcached __P((struct hash_table *ht, const void *item));
     92void *hash_delete_strcached __P((struct hash_table *ht, void const *item));
     93#endif /* CONFIG_WITH_STRCACHE2 */
     94
    8695extern void *hash_deleted_item;
    8796#define HASH_VACANT(item) ((item) == 0 || (void *) (item) == hash_deleted_item)
  • 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.

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