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


Ignore:
Timestamp:
Oct 20, 2008, 4:00:45 AM (17 years ago)
Author:
bird
Message:

kmk: file.c - use strcache2_lookup when an uncached string is handed to lookup. hash/cmp callbacks can now assume that all is string cached.

File:
1 edited

Legend:

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

    r1881 r1892  
    4141/* Hash table of files the makefile knows how to make.  */
    4242
    43 #ifndef KMK
    4443static unsigned long
    4544file_hash_1 (const void *key)
    4645{
     46#ifndef CONFIG_WITH_STRCACHE2
    4747  return_ISTRING_HASH_1 (((struct file const *) key)->hname);
     48#else  /* CONFIG_WITH_STRCACHE2 */
     49  return strcache_get_hash1 (((struct file const *) key)->hname);
     50#endif /* CONFIG_WITH_STRCACHE2 */
    4851}
    4952
     
    5154file_hash_2 (const void *key)
    5255{
     56#ifndef CONFIG_WITH_STRCACHE2
    5357  return_ISTRING_HASH_2 (((struct file const *) key)->hname);
     58#else  /* CONFIG_WITH_STRCACHE2 */
     59  return strcache_get_hash1 (((struct file const *) key)->hname);
     60#endif /* CONFIG_WITH_STRCACHE2 */
    5461}
    5562
     
    5764file_hash_cmp (const void *x, const void *y)
    5865{
     66#ifndef CONFIG_WITH_STRCACHE2
    5967  return_ISTRING_COMPARE (((struct file const *) x)->hname,
    6068                          ((struct file const *) y)->hname);
    61 }
    62 #else  /* KMK */
    63 
    64 static unsigned long
    65 file_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 
    76 static unsigned long
    77 file_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 
    88 static int
    89 file_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 
    101   if (xf->hname == yf->hname)
    102     return 0;
    103   if (   xf->name != (const char *)xf
    104       && yf->name != (const char *)yf)
    105     return 1;
    106 
    107   return_ISTRING_COMPARE (xf->hname, yf->hname);
    108 }
    109 
    110 #endif /* KMK */
     69#else  /* CONFIG_WITH_STRCACHE2 */
     70  return ((struct file const *) x)->hname
     71      == ((struct file const *) y)->hname ? 0 : -1;
     72#endif /* CONFIG_WITH_STRCACHE2 */
     73}
    11174
    11275#ifndef FILE_BUCKETS
     
    177140#endif
    178141
    179 #ifdef KMK
    180   /* uncached lookup indicator hack. */
    181   file_key.name = !cached ? (const char *)&file_key : NULL;
    182 #endif
     142#ifndef CONFIG_WITH_STRCACHE2
    183143  file_key.hname = name;
    184144  f = hash_find_item (&files, &file_key);
     145#else  /* CONFIG_WITH_STRCACHE2 */
     146  if (!cached)
     147    {
     148      file_key.hname = strcache2_lookup (&file_strcache, name, strlen (name));
     149      if (file_key.hname)
     150        f = hash_find_item (&files, &file_key);
     151      else
     152        f = NULL;
     153    }
     154  else
     155    {
     156      file_key.hname = name;
     157      f = hash_find_item (&files, &file_key);
     158    }
     159
     160#endif /* CONFIG_WITH_STRCACHE2 */
    185161#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
    186162  if (*name != '.')
     
    297273  struct file *f;
    298274
    299 #ifdef KMK
     275#ifdef CONFIG_WITH_STRCACHE2
    300276  assert (strcache_iscached (to_hname));
    301277  assert (strcache_iscached (from_file->hname));
    302   file_key.name = NULL; /* cached lookup indicator hack. */
    303278#endif
    304279
Note: See TracChangeset for help on using the changeset viewer.