Changeset 1853 for trunk/src/kmk/read.c


Ignore:
Timestamp:
Oct 13, 2008, 3:46:35 AM (17 years ago)
Author:
bird
Message:

kmk: Optimized the dependency hashing done by uniquize_deps() by making it take advantage of the fact that all strings are in the strcache.

File:
1 edited

Legend:

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

    r1846 r1853  
    21242124
    21252125/* Remove duplicate dependencies in CHAIN.  */
     2126#ifndef CONFIG_WITH_VALUE_LENGTH
    21262127
    21272128static unsigned long
     
    21542155}
    21552156
     2157#else  /* CONFIG_WITH_VALUE_LENGTH */
     2158
     2159/* Exploit the fact that all names are in the string cache. This means equal
     2160   names shall have the same storage and there is no need for hashing or
     2161   comparing. Use the address as the first hash, avoiding any touching of
     2162   the name, and the length as the second. */
     2163
     2164static unsigned long
     2165dep_hash_1 (const void *key)
     2166{
     2167  const char *name = dep_name ((struct dep const *) key);
     2168  assert (strcache_iscached (name));
     2169  return (size_t) name / sizeof(void *);
     2170}
     2171
     2172static unsigned long
     2173dep_hash_2 (const void *key)
     2174{
     2175  const char *name = dep_name ((struct dep const *) key);
     2176  return strcache_get_len (name);
     2177}
     2178
     2179static int
     2180dep_hash_cmp (const void *x, const void *y)
     2181{
     2182  struct dep *dx = (struct dep *) x;
     2183  struct dep *dy = (struct dep *) y;
     2184  const char *dxname = dep_name (dx);
     2185  const char *dyname = dep_name (dy);
     2186  int cmp = dxname == dyname ? 0 : 1;
     2187
     2188  /* check preconds: both cached and the cache contains no duplicates. */
     2189  assert (strcache_iscached (dxname));
     2190  assert (strcache_iscached (dyname));
     2191  assert (cmp == 0 || strcmp (dxname, dyname) != 0);
     2192
     2193  /* If the names are the same but ignore_mtimes are not equal, one of these
     2194     is an order-only prerequisite and one isn't.  That means that we should
     2195     remove the one that isn't and keep the one that is.  */
     2196
     2197  if (!cmp && dx->ignore_mtime != dy->ignore_mtime)
     2198    dx->ignore_mtime = dy->ignore_mtime = 0;
     2199
     2200  return cmp;
     2201}
     2202
     2203#endif /* CONFIG_WITH_VALUE_LENGTH */
    21562204
    21572205void
     
    24672515          /* Single-colon.  Combine these dependencies
    24682516             with others in file's existing record, if any.  */
     2517#ifndef KMK
    24692518          f = enter_file (strcache_add (name));
     2519#else  /* KMK - the name is already in the cache, don't waste time.  */
     2520          f = enter_file (name);
     2521#endif
    24702522
    24712523          if (f->double_colon)
Note: See TracChangeset for help on using the changeset viewer.