VirtualBox

Changeset 1845 in kBuild for trunk/src/kmk


Ignore:
Timestamp:
Oct 12, 2008 4:23:10 PM (16 years ago)
Author:
bird
Message:

kmk/strcache: Make use of the string length to avoid expensive compare calls. (sorted out 38% of the calls in a kBuild test)

File:
1 edited

Legend:

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

    r1844 r1845  
    130130/* Hash table of strings in the cache.  */
    131131
     132#ifdef CONFIG_WITH_VALUE_LENGTH
     133static const char *lookup_string;
     134static unsigned int lookup_string_len;
     135#endif
     136
    132137static unsigned long
    133138str_hash_1 (const void *key)
     
    145150str_hash_cmp (const void *x, const void *y)
    146151{
     152#ifdef CONFIG_WITH_VALUE_LENGTH
     153  /* Use the string length to avoid some unncessary comparing.
     154     X is either the add_hash input (during hash_find_slot)
     155     or a cache entry (during rare hash_insert_at calls).
     156     This catches 520253 out of 1341947 calls in the typical
     157     kBuild scenario.  */
     158
     159  if (x == lookup_string)
     160    {
     161      assert (lookup_string_len == strlen ((const char *)x));
     162      if (strcache_get_len ((const char *)y) != lookup_string_len)
     163        return -1;
     164    }
     165#endif
    147166  return_ISTRING_COMPARE ((const char *) x, (const char *) y);
    148167}
     
    155174{
    156175  /* Look up the string in the hash.  If it's there, return it.  */
     176#ifndef CONFIG_WITH_VALUE_LENGTH
    157177  char *const *slot = (char *const *) hash_find_slot (&strings, str);
    158178  const char *key = *slot;
     179#else  /* CONFIG_WITH_VALUE_LENGTH */
     180  char *const *slot;
     181  const char *key;
     182
     183  lookup_string = str;
     184  lookup_string_len = len;
     185  slot = (char *const *) hash_find_slot (&strings, str);
     186  key = *slot;
     187#endif /* CONFIG_WITH_VALUE_LENGTH */
    159188
    160189  /* Count the total number of adds we performed.  */
Note: See TracChangeset for help on using the changeset viewer.

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