Changeset 1885 for trunk/src/kmk


Ignore:
Timestamp:
Oct 19, 2008, 11:30:02 PM (17 years ago)
Author:
bird
Message:

kmk: strcache2_add_file macro for wrapping case sensitive/insenstive hashing, avoiding a couple of checks a lots of inlined code in strcache2.

Location:
trunk/src/kmk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/make.h

    r1872 r1885  
    644644
    645645# define strcache_iscached(str)     strcache2_is_cached(&file_strcache, str)
    646 # define strcache_add(str)          strcache2_add(&file_strcache, str, strlen (str))
    647 # define strcache_add_len(str, len) strcache2_add(&file_strcache, str, len)
     646# define strcache_add(str)          strcache2_add_file(&file_strcache, str, strlen (str))
     647# define strcache_add_len(str, len) strcache2_add_file(&file_strcache, str, len)
    648648# ifdef CONFIG_WITH_INCLUDEDEP
    649649#  define strcache_add_prehashed(str, len, hash1, hash2) \
  • trunk/src/kmk/strcache2.c

    r1879 r1885  
    6161
    6262
     63/*******************************************************************************
     64*   Global Variables                                                           *
     65*******************************************************************************/
     66/* List of initialized string caches. */
     67static struct strcache2 *strcache_head;
     68
    6369
    6470
     
    375381  struct strcache2_entry const *entry;
    376382  unsigned int hash2;
    377   unsigned int hash1 = cache->case_insensitive
    378     ? strcache2_case_insensitive_hash_1 (str, length)
    379     : strcache2_case_sensitive_hash_1 (str, length);
     383  unsigned int hash1 = strcache2_case_sensitive_hash_1 (str, length);
    380384  unsigned int idx;
     385
     386  assert (!cache->case_insensitive);
     387
    381388
    382389  cache->lookup_count++;
     
    394401      cache->collision_1st_count++;
    395402
    396       hash2 = cache->case_insensitive
    397         ? strcache2_case_insensitive_hash_2 (str, length)
    398         : strcache2_case_sensitive_hash_2 (str, length);
     403      hash2 = strcache2_case_sensitive_hash_2 (str, length);
    399404      idx += hash2;
    400405      idx &= cache->hash_mask;
     
    489494}
    490495
     496#if defined(HAVE_CASE_INSENSITIVE_FS)
     497
     498/* The public add/lookup string interface for case insensitive strings. */
     499const char *
     500strcache2_iadd (struct strcache2 *cache, const char *str, unsigned int length)
     501{
     502  struct strcache2_entry const *entry;
     503  unsigned int hash2;
     504  unsigned int hash1 = strcache2_case_insensitive_hash_1 (str, length);
     505  unsigned int idx;
     506
     507  assert (cache->case_insensitive);
     508  cache->lookup_count++;
     509
     510  /* Lookup the entry in the hash table, hoping for an
     511     early match. */
     512  idx = hash1 & cache->hash_mask;
     513  entry = cache->hash_tab[idx];
     514  if (strcache2_is_equal (cache, entry, str, length, hash1))
     515    return (const char *)(entry + 1);
     516  if (!entry)
     517    hash2 = 0;
     518  else
     519    {
     520      cache->collision_1st_count++;
     521
     522      hash2 = strcache2_case_insensitive_hash_2 (str, length);
     523      idx += hash2;
     524      idx &= cache->hash_mask;
     525      entry = cache->hash_tab[idx];
     526      if (strcache2_is_equal (cache, entry, str, length, hash1))
     527        return (const char *)(entry + 1);
     528
     529      if (entry)
     530        {
     531          cache->collision_2nd_count++;
     532          do
     533            {
     534              idx += hash2;
     535              idx &= cache->hash_mask;
     536              entry = cache->hash_tab[idx];
     537              cache->collision_3rd_count++;
     538              if (strcache2_is_equal (cache, entry, str, length, hash1))
     539                return (const char *)(entry + 1);
     540            }
     541          while (entry);
     542        }
     543    }
     544
     545  /* Not found, add it at IDX. */
     546  return strcache2_enter_string (cache, idx, str, length, hash1, hash2);
     547}
     548
     549/* strcache_ilookup later */
     550
     551#endif /* HAVE_CASE_INSENSITIVE_FS */
     552
    491553/* Is the given string cached? returns 1 if it is, 0 if it isn't. */
    492554int
     
    591653
    592654
    593 /* List of initialized string caches. */
    594 static struct strcache2 *strcache_head;
    595655
    596656/* Initalizes a new cache. */
  • trunk/src/kmk/strcache2.h

    r1870 r1885  
    7474void strcache2_print_stats_all (const char *prefix);
    7575const char *strcache2_add (struct strcache2 *cache, const char *str, unsigned int length);
     76const char *strcache2_iadd (struct strcache2 *cache, const char *str, unsigned int length);
     77#ifdef HAVE_CASE_INSENSITIVE_FS
     78# define strcache2_add_file(cache, str, length) strcache2_iadd((cache), (str), (length))
     79#else
     80# define strcache2_add_file(cache, str, length) strcache2_add((cache), (str), (length))
     81#endif
    7682const char *strcache2_add_hashed (struct strcache2 *cache, const char *str, unsigned int length,
    7783                                  unsigned int hash1, unsigned int hash2);
Note: See TracChangeset for help on using the changeset viewer.