Changeset 1897 for trunk/src/kmk


Ignore:
Timestamp:
Oct 21, 2008, 3:21:39 AM (17 years ago)
Author:
bird
Message:

kmk: added strcache2_get_ptr_hash for more efficent hashing by string pool users; replacing hash1 with that and hash2 with hash1, thus avoiding unnecessary hash2 calculations.

Location:
trunk/src/kmk
Files:
6 edited

Legend:

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

    r1891 r1897  
    264264  ISTRING_HASH_1 (key->path_key, hash);
    265265# else  /* CONFIG_WITH_STRCACHE2 */
    266   hash = strcache_get_hash1 (key->path_key);
     266  hash = strcache2_get_ptr_hash (&file_cache, key->path_key);
    267267# endif /* CONFIG_WITH_STRCACHE2 */
    268268  hash ^= ((unsigned int) key->dev << 4) ^ (unsigned int) key->ctime;
     
    291291  ISTRING_HASH_2 (key->path_key, hash);
    292292# else  /* CONFIG_WITH_STRCACHE2 */
    293   hash = strcache_get_hash2 (key->path_key);
     293  hash = strcache2_get_hash1 (&file_cache, key->path_key);
    294294# endif /* CONFIG_WITH_STRCACHE2 */
    295295  hash ^= ((unsigned int) key->dev << 4) ^ (unsigned int) ~key->ctime;
     
    383383  return_ISTRING_HASH_1 (((const struct directory *) key)->name);
    384384#else
    385   return strcache_get_hash1 (((const struct directory *) key)->name);
     385  return strcache2_get_ptr_hash (&file_cache, ((const struct directory *) key)->name);
    386386#endif
    387387}
     
    393393  return_ISTRING_HASH_2 (((const struct directory *) key)->name);
    394394#else
    395   return strcache_get_hash2 (((const struct directory *) key)->name);
     395  return strcache2_get_hash1 (&file_cache, ((const struct directory *) key)->name);
    396396#endif
    397397}
     
    439439  return_ISTRING_HASH_1 (((struct dirfile const *) key)->name);
    440440#else
    441   return strcache_get_hash1 (((struct dirfile const *) key)->name);
     441  return strcache2_get_ptr_hash (&file_cache, ((struct dirfile const *) key)->name);
    442442#endif
    443443}
     
    449449  return_ISTRING_HASH_2 (((struct dirfile const *) key)->name);
    450450#else
    451   return strcache_get_hash2 (((struct dirfile const *) key)->name);
     451  return strcache2_get_hash1 (&file_cache, ((struct dirfile const *) key)->name);
    452452#endif
    453453}
  • trunk/src/kmk/file.c

    r1892 r1897  
    4747  return_ISTRING_HASH_1 (((struct file const *) key)->hname);
    4848#else  /* CONFIG_WITH_STRCACHE2 */
    49   return strcache_get_hash1 (((struct file const *) key)->hname);
     49  return strcache2_get_ptr_hash (&file_cache, ((struct file const *) key)->hname);
    5050#endif /* CONFIG_WITH_STRCACHE2 */
    5151}
     
    5757  return_ISTRING_HASH_2 (((struct file const *) key)->hname);
    5858#else  /* CONFIG_WITH_STRCACHE2 */
    59   return strcache_get_hash1 (((struct file const *) key)->hname);
     59  return strcache2_get_ptr_hash (&file_cache, ((struct file const *) key)->hname);
    6060#endif /* CONFIG_WITH_STRCACHE2 */
    6161}
  • trunk/src/kmk/make.h

    r1896 r1897  
    601601# define strcache_add(str)          strcache2_add_file(&file_strcache, str, strlen (str))
    602602# define strcache_add_len(str, len) strcache2_add_file(&file_strcache, str, len)
    603 # define strcache_get_len(str)      strcache2_get_len(&file_strcache, str)
    604 # define strcache_get_hash1(str)    strcache2_get_hash1(&file_strcache, str)
    605 # define strcache_get_hash2(str)    strcache2_get_hash2(&file_strcache, str)
     603# define strcache_get_len(str)      strcache2_get_len(&file_strcache, str) /* FIXME: replace this and related checks ... */
    606604
    607605#endif /* CONFIG_WITH_STRCACHE2 */
  • trunk/src/kmk/strcache2.c

    r1888 r1897  
    526526
    527527  size = length + 1 + sizeof (struct strcache2_entry);
    528   size = (size + sizeof (void *) - 1) & ~(sizeof (void *) - 1U);
     528  size = (size + STRCACHE2_ENTRY_ALIGNMENT - 1) & ~(STRCACHE2_ENTRY_ALIGNMENT - 1U);
    529529
    530530  seg = cache->seg_head;
  • trunk/src/kmk/strcache2.h

    r1887 r1897  
    2828#define ___strcache2_h
    2929
     30#ifndef CHAR_BIT
     31# error "include after make.h!"
     32#endif
     33
    3034/* string cache memory segment. */
    3135struct strcache2_seg
     
    4650    unsigned int length;
    4751};
     52
     53/* The entry alignment.
     54   As it is very difficult to derive this from any #define or typedef, a
     55   default value of 16 (chars) was choosen as this fits most platforms.
     56   For odd platforms, just override this define.  */
     57#ifndef STRCACHE2_ENTRY_ALIGN_SHIFT
     58# define STRCACHE2_ENTRY_ALIGN_SHIFT    4
     59#endif
     60#define STRCACHE2_ENTRY_ALIGNMENT       (1 << STRCACHE2_ENTRY_ALIGN_SHIFT)
     61
    4862
    4963struct strcache2
     
    123137}
    124138
     139/* Get the pointer hash value for the string.
     140
     141   This takes the string address, shift out the bits that are always zero
     142   due to alignment, and then returns the unsigned integer value of it.
     143
     144   The results from using this is generally better than for any of the
     145   other hash values.  It is also sligtly faster code as it does not
     146   involve any memory accesses, just a right SHIFT and an optional AND. */
     147MY_INLINE unsigned int
     148strcache2_get_ptr_hash (struct strcache2 *cache, const char *str)
     149{
     150  (void)cache;
     151  return (size_t)str >> STRCACHE2_ENTRY_ALIGN_SHIFT;
     152}
     153
    125154/* Get the user value for the string. */
    126155MY_INLINE void *
  • trunk/src/kmk/variable.c

    r1890 r1897  
    118118#else
    119119  /* all requests are served from the cache. */
    120   return strcache2_get_hash1 (&variable_strcache, key->name);
     120  return strcache2_get_ptr_hash (&variable_strcache, key->name);
    121121#endif
    122122}
     
    485485#ifdef KMK /* bird: speed */
    486486      struct hash_table *ht = &setlist->set->table;
    487       unsigned int hash_1 = strcache2_get_hash1 (&variable_strcache, name);
     487      unsigned int hash_1 = strcache2_get_ptr_hash (&variable_strcache, name);
    488488      struct variable *v;
    489489
Note: See TracChangeset for help on using the changeset viewer.