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.

File:
1 edited

Legend:

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