Changeset 1857 for trunk/src/kmk/file.c


Ignore:
Timestamp:
Oct 13, 2008, 5:58:07 AM (17 years ago)
Author:
bird
Message:

kmk: improved the hashing of file table entries by making the strcache cache their hash values along with the string length.

File:
1 edited

Legend:

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

    r1851 r1857  
    4141/* Hash table of files the makefile knows how to make.  */
    4242
     43#ifndef KMK
    4344static unsigned long
    4445file_hash_1 (const void *key)
     
    5657file_hash_cmp (const void *x, const void *y)
    5758{
    58 #ifdef KMK
    59  /* since the names live in the strcache, there is a raging likelylood
    60     that we'll match on the string pointer.  Which is wee bit faster...  */
    61  struct file const *xf = ((struct file const *) x);
    62  struct file const *yf = ((struct file const *) y);
     59  return_ISTRING_COMPARE (((struct file const *) x)->hname,
     60                          ((struct file const *) y)->hname);
     61}
     62#else  /* KMK */
     63
     64static unsigned long
     65file_hash_1 (const void *key)
     66{
     67  struct file const *f = (struct file const *)key;
     68
     69  /* If it's cached, get the hash from the strcache. */
     70  if (f->name != (const char *)f)
     71    return strcache_get_hash1 (f->hname);
     72
     73  return_ISTRING_HASH_1 (f->hname);
     74}
     75
     76static unsigned long
     77file_hash_2 (const void *key)
     78{
     79  struct file const *f = (struct file const *)key;
     80
     81  /* If it's cached, get the hash from the strcache. */
     82  if (f->name != (const char *)f)
     83    return strcache_get_hash2 (f->hname);
     84
     85  return_ISTRING_HASH_2 (f->hname);
     86}
     87
     88static int
     89file_hash_cmp (const void *x, const void *y)
     90{
     91  struct file const *xf = ((struct file const *) x);
     92  struct file const *yf = ((struct file const *) y);
     93
     94  /* The file name strings all live in the strcache. However,
     95     lookup_file may or may not have a string from the cache. It indicates
     96     that it's responsible for the lookup by setting file::name to point
     97     to the file structure itself. So, when file::name points elsewhere
     98     we can omit the string compare, while when it isn't we can only
     99     check if they match that way. */
     100
    63101  if (xf->hname == yf->hname)
    64102    return 0;
     103  if (   xf->name != (const char *)xf
     104      && yf->name != (const char *)yf)
     105    return 1;
     106
    65107  return_ISTRING_COMPARE (xf->hname, yf->hname);
    66 #else
    67   return_ISTRING_COMPARE (((struct file const *) x)->hname,
    68                           ((struct file const *) y)->hname);
    69 #endif
    70 }
     108}
     109
     110#endif /* KMK */
    71111
    72112#ifndef FILE_BUCKETS
     
    83123*/
    84124
     125#ifndef KMK
    85126struct file *
    86127lookup_file (const char *name)
     128#else  /* KMK */
     129MY_INLINE struct file *
     130lookup_file_common (const char *name, int cached)
     131#endif /* KMK */
    87132{
    88133  struct file *f;
     
    132177#endif
    133178
     179#ifdef KMK
     180  /* uncached lookup indicator hack. */
     181  file_key.name = !cached ? (const char *)&file_key : NULL;
     182#endif
    134183  file_key.hname = name;
    135184  f = hash_find_item (&files, &file_key);
     
    141190  return f;
    142191}
     192
     193#ifdef KMK
     194/* Given a name, return the struct file * for that name,
     195  or nil if there is none. */
     196
     197struct file *
     198lookup_file (const char *name)
     199{
     200  return lookup_file_common (name, 0 /* cached */);
     201}
     202
     203/* Given a name in the strcache, return the struct file * for that name,
     204  or nil if there is none. */
     205struct file *
     206lookup_file_cached (const char *name)
     207{
     208  assert (strcache_iscached (name));
     209  return lookup_file_common (name, 1 /* cached */);
     210}
     211#endif /* KMK */
     212
    143213
    144214/* Look up a file record for file NAME and return it.
     
    222292  struct file *deleted_file;
    223293  struct file *f;
     294
     295#ifdef KMK
     296  assert (strcache_iscached (to_hname));
     297  assert (strcache_iscached (from_file->hname));
     298  file_key.name = NULL; /* cached lookup indicator hack. */
     299#endif
    224300
    225301  /* If it's already that name, we're done.  */
Note: See TracChangeset for help on using the changeset viewer.