Changeset 1902 for trunk/src/kmk/dir.c


Ignore:
Timestamp:
Oct 21, 2008, 5:57:00 AM (17 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/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,
Note: See TracChangeset for help on using the changeset viewer.