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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 *
Note: See TracChangeset for help on using the changeset viewer.