VirtualBox

Changeset 1903 in kBuild


Ignore:
Timestamp:
Oct 21, 2008 4:25:19 AM (16 years ago)
Author:
bird
Message:

strcache2: some cleanup.

Location:
trunk/src/kmk
Files:
4 edited

Legend:

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

    r1902 r1903  
    140140  if (!cached)
    141141    {
    142       file_key.hname = strcache2_lookup (&file_strcache, name, strlen (name));
     142      file_key.hname = strcache2_lookup_file (&file_strcache, name, strlen (name));
    143143      if (file_key.hname)
    144144        f = hash_find_item_strcached (&files, &file_key);
  • trunk/src/kmk/incdep.c

    r1895 r1903  
    769769{
    770770  if (!entry->user)
    771     entry->user = (void *)strcache2_add_hashed (&file_strcache,
    772                                                 (const char *)(entry + 1),
    773                                                 entry->length,
    774                                                 entry->hash1,
    775                                                 entry->hash2);
     771    entry->user = (void *)strcache2_add_hashed_file (&file_strcache,
     772                                                     (const char *)(entry + 1),
     773                                                     entry->length,
     774                                                     entry->hash1,
     775                                                     entry->hash2);
    776776  return (const char *)entry->user;
    777777}
  • trunk/src/kmk/strcache2.c

    r1899 r1903  
    268268}
    269269
    270 #if 0 /* FIXME: Use this (salvaged from variable.c) */
     270#ifdef _MSC_VER
     271  typedef unsigned int int32_t;
     272#else
     273# include <stdint.h>
     274#endif
    271275
    272276MY_INLINE int
    273 variable_hash_cmp_2_memcmp (const char *xs, const char *ys, unsigned int length)
     277strcache2_memcmp_inline_short (const char *xs, const char *ys, unsigned int length)
    274278{
    275279  /* short string compare - ~50% of the kBuild calls. */
     
    345349
    346350MY_INLINE int
    347 variable_hash_cmp_2_inlined (const char *xs, const char *ys, unsigned int length)
     351strcache2_memcmp_inlined (const char *xs, const char *ys, unsigned int length)
    348352{
    349353#ifndef ELECTRIC_HEAP
     
    450454}
    451455
    452 #endif
    453 
    454456MY_INLINE int
    455457strcache2_is_equal (struct strcache2 *cache, struct strcache2_entry const *entry,
    456458                    const char *str, unsigned int length, unsigned int hash1)
    457459{
     460  assert (!cache->case_insensitive);
     461
    458462  /* the simple stuff first. */
    459463  if (   entry == NULL
     
    462466      return 0;
    463467
    464   return !cache->case_insensitive
    465     ? memcmp (entry + 1, str, length) == 0
     468#if 1
     469  return memcmp (entry + 1, str, length) == 0;
     470#elif 0
     471  return strcache2_memcmp_inlined (entry + 1, str, length) == 0;
     472#else
     473  return strcache2_memcmp_inline_short (entry + 1, str, length) == 0;
     474#endif
     475}
     476
     477MY_INLINE int
     478strcache2_is_iequal (struct strcache2 *cache, struct strcache2_entry const *entry,
     479                     const char *str, unsigned int length, unsigned int hash1)
     480{
     481  assert (cache->case_insensitive);
     482
     483  /* the simple stuff first. */
     484  if (   entry == NULL
     485      || entry->hash1 != hash1
     486      || entry->length != length)
     487      return 0;
     488
    466489#if defined(_MSC_VER) || defined(__OS2__)
    467     : _memicmp (entry + 1, str, length) == 0
     490  return _memicmp (entry + 1, str, length) == 0;
    468491#else
    469     : strncasecmp ((const char *)(entry + 1), str, length) == 0
     492  return strncasecmp ((const char *)(entry + 1), str, length) == 0;
    470493#endif
    471     ;
    472494}
    473495
     
    632654  unsigned correct_hash;
    633655
    634   correct_hash = cache->case_insensitive
    635                ? strcache2_case_insensitive_hash_1 (str, length)
    636                : strcache2_case_sensitive_hash_1 (str, length);
     656  assert (!cache->case_insensitive);
     657  correct_hash = strcache2_case_sensitive_hash_1 (str, length);
    637658  MY_ASSERT_MSG (hash1 == correct_hash, ("%#x != %#x\n", hash1, correct_hash));
    638659  if (hash2)
    639660    {
    640       correct_hash = cache->case_insensitive
    641                    ? strcache2_case_insensitive_hash_2 (str, length)
    642                    : strcache2_case_sensitive_hash_2 (str, length);
     661      correct_hash = strcache2_case_sensitive_hash_2 (str, length);
    643662      MY_ASSERT_MSG (hash2 == correct_hash, ("%#x != %#x\n", hash2, correct_hash));
    644663    }
     
    687706}
    688707
    689 /* The public lookup string interface. */
     708/* The public lookup (case sensitive) string interface. */
    690709const char *
    691710strcache2_lookup (struct strcache2 *cache, const char *str, unsigned int length)
     
    757776  idx = hash1 & cache->hash_mask;
    758777  entry = cache->hash_tab[idx];
    759   if (strcache2_is_equal (cache, entry, str, length, hash1))
     778  if (strcache2_is_iequal (cache, entry, str, length, hash1))
    760779    return (const char *)(entry + 1);
    761780  if (!entry)
     
    769788      idx &= cache->hash_mask;
    770789      entry = cache->hash_tab[idx];
    771       if (strcache2_is_equal (cache, entry, str, length, hash1))
     790      if (strcache2_is_iequal (cache, entry, str, length, hash1))
    772791        return (const char *)(entry + 1);
    773792
     
    781800              entry = cache->hash_tab[idx];
    782801              cache->collision_3rd_count++;
    783               if (strcache2_is_equal (cache, entry, str, length, hash1))
     802              if (strcache2_is_iequal (cache, entry, str, length, hash1))
    784803                return (const char *)(entry + 1);
    785804            }
     
    792811}
    793812
    794 /* strcache_ilookup later */
     813/* The public add string interface for prehashed case insensitive strings.
     814   Use strcache2_hash_istr to calculate the hash of a string. */
     815const char *
     816strcache2_iadd_hashed (struct strcache2 *cache, const char *str, unsigned int length,
     817                       unsigned int hash1, unsigned int hash2)
     818{
     819  struct strcache2_entry const *entry;
     820  unsigned int idx;
     821#ifndef NDEBUG
     822  unsigned correct_hash;
     823
     824  assert (cache->case_insensitive);
     825  correct_hash = strcache2_case_insensitive_hash_1 (str, length);
     826  MY_ASSERT_MSG (hash1 == correct_hash, ("%#x != %#x\n", hash1, correct_hash));
     827  if (hash2)
     828    {
     829      correct_hash = strcache2_case_insensitive_hash_2 (str, length);
     830      MY_ASSERT_MSG (hash2 == correct_hash, ("%#x != %#x\n", hash2, correct_hash));
     831    }
     832#endif /* NDEBUG */
     833
     834  cache->lookup_count++;
     835
     836  /* Lookup the entry in the hash table, hoping for an
     837     early match. */
     838  idx = hash1 & cache->hash_mask;
     839  entry = cache->hash_tab[idx];
     840  if (strcache2_is_iequal (cache, entry, str, length, hash1))
     841    return (const char *)(entry + 1);
     842  if (entry)
     843    {
     844      cache->collision_1st_count++;
     845
     846      if (!hash2)
     847        hash2 = strcache2_case_insensitive_hash_2 (str, length);
     848      idx += hash2;
     849      idx &= cache->hash_mask;
     850      entry = cache->hash_tab[idx];
     851      if (strcache2_is_iequal (cache, entry, str, length, hash1))
     852        return (const char *)(entry + 1);
     853
     854      if (entry)
     855        {
     856          cache->collision_2nd_count++;
     857          do
     858            {
     859              idx += hash2;
     860              idx &= cache->hash_mask;
     861              entry = cache->hash_tab[idx];
     862              cache->collision_3rd_count++;
     863              if (strcache2_is_iequal (cache, entry, str, length, hash1))
     864                return (const char *)(entry + 1);
     865            }
     866          while (entry);
     867        }
     868    }
     869
     870  /* Not found, add it at IDX. */
     871  return strcache2_enter_string (cache, idx, str, length, hash1, hash2);
     872}
     873
     874/* The public lookup (case insensitive) string interface. */
     875const char *
     876strcache2_lookup (struct strcache2 *cache, const char *str, unsigned int length)
     877{
     878  struct strcache2_entry const *entry;
     879  unsigned int hash2;
     880  unsigned int hash1 = strcache2_case_insensitive_hash_1 (str, length);
     881  unsigned int idx;
     882
     883  assert (cache->case_insensitive);
     884
     885  cache->lookup_count++;
     886
     887  /* Lookup the entry in the hash table, hoping for an
     888     early match. */
     889  idx = hash1 & cache->hash_mask;
     890  entry = cache->hash_tab[idx];
     891  if (strcache2_is_iequal (cache, entry, str, length, hash1))
     892    return (const char *)(entry + 1);
     893  if (!entry)
     894    hash2 = 0;
     895  else
     896    {
     897      cache->collision_1st_count++;
     898
     899      hash2 = strcache2_case_insensitive_hash_2 (str, length);
     900      idx += hash2;
     901      idx &= cache->hash_mask;
     902      entry = cache->hash_tab[idx];
     903      if (strcache2_is_iequal (cache, entry, str, length, hash1))
     904        return (const char *)(entry + 1);
     905
     906      if (entry)
     907        {
     908          cache->collision_2nd_count++;
     909          do
     910            {
     911              idx += hash2;
     912              idx &= cache->hash_mask;
     913              entry = cache->hash_tab[idx];
     914              cache->collision_3rd_count++;
     915              if (strcache2_is_iequal (cache, entry, str, length, hash1))
     916                return (const char *)(entry + 1);
     917            }
     918          while (entry);
     919        }
     920    }
     921
     922  /* Not found. */
     923  return NULL;
     924}
    795925
    796926#endif /* HAVE_CASE_INSENSITIVE_FS */
  • trunk/src/kmk/strcache2.h

    r1900 r1903  
    9595const char *strcache2_add (struct strcache2 *cache, const char *str, unsigned int length);
    9696const char *strcache2_iadd (struct strcache2 *cache, const char *str, unsigned int length);
    97 #ifdef HAVE_CASE_INSENSITIVE_FS
    98 # define strcache2_add_file(cache, str, length) strcache2_iadd((cache), (str), (length))
    99 #else
    100 # define strcache2_add_file(cache, str, length) strcache2_add((cache), (str), (length))
    101 #endif
    10297const char *strcache2_add_hashed (struct strcache2 *cache, const char *str, unsigned int length,
    10398                                  unsigned int hash1, unsigned int hash2);
     99const char *strcache2_iadd_hashed (struct strcache2 *cache, const char *str, unsigned int length,
     100                                   unsigned int hash1, unsigned int hash2);
    104101const char *strcache2_lookup (struct strcache2 *cache, const char *str, unsigned int length);
     102const char *strcache2_ilookup (struct strcache2 *cache, const char *str, unsigned int length);
     103#ifdef HAVE_CASE_INSENSITIVE_FS
     104# define strcache2_add_file         strcache2_iadd
     105# define strcache2_add_hashed_file  strcache2_iadd_hashed
     106# define strcache2_lookup_file      strcache2_ilookup
     107#else
     108# define strcache2_add_file         strcache2_add
     109# define strcache2_add_hashed_file  strcache2_add_hashed
     110# define strcache2_lookup_file      strcache2_lookup
     111#endif
    105112int strcache2_is_cached (struct strcache2 *cache, const char *str);
    106113int strcache2_verify_entry (struct strcache2 *cache, const char *str);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette