Index: trunk/src/kmk/dir.c
===================================================================
--- trunk/src/kmk/dir.c	(revision 1901)
+++ trunk/src/kmk/dir.c	(revision 1902)
@@ -377,12 +377,9 @@
   };
 
+#ifndef CONFIG_WITH_STRCACHE2
 static unsigned long
 directory_hash_1 (const void *key)
 {
-#ifndef CONFIG_WITH_STRCACHE2
   return_ISTRING_HASH_1 (((const struct directory *) key)->name);
-#else
-  return strcache2_get_ptr_hash (&file_strcache, ((const struct directory *) key)->name);
-#endif
 }
 
@@ -390,9 +387,5 @@
 directory_hash_2 (const void *key)
 {
-#ifndef CONFIG_WITH_STRCACHE2
   return_ISTRING_HASH_2 (((const struct directory *) key)->name);
-#else
-  return strcache2_get_hash1 (&file_strcache, ((const struct directory *) key)->name);
-#endif
 }
 
@@ -400,12 +393,8 @@
 directory_hash_cmp (const void *x, const void *y)
 {
-#ifndef CONFIG_WITH_STRCACHE2
   return_ISTRING_COMPARE (((const struct directory *) x)->name,
 			  ((const struct directory *) y)->name);
-#else
-  return ((const struct directory *) x)->name
-      == ((const struct directory *) y)->name ? 0 : -1;
-#endif
-}
+}
+#endif /* !CONFIG_WITH_STRCACHE2 */
 
 /* Table of directories hashed by name.  */
@@ -433,12 +422,9 @@
   };
 
+#ifndef CONFIG_WITH_STRCACHE2
 static unsigned long
 dirfile_hash_1 (const void *key)
 {
-#ifndef CONFIG_WITH_STRCACHE2
   return_ISTRING_HASH_1 (((struct dirfile const *) key)->name);
-#else
-  return strcache2_get_ptr_hash (&file_strcache, ((struct dirfile const *) key)->name);
-#endif
 }
 
@@ -446,9 +432,5 @@
 dirfile_hash_2 (const void *key)
 {
-#ifndef CONFIG_WITH_STRCACHE2
   return_ISTRING_HASH_2 (((struct dirfile const *) key)->name);
-#else
-  return strcache2_get_hash1 (&file_strcache, ((struct dirfile const *) key)->name);
-#endif
 }
 
@@ -458,13 +440,10 @@
   const struct dirfile *x = xv;
   const struct dirfile *y = yv;
-#ifndef CONFIG_WITH_STRCACHE2
   int result = x->length - y->length;
   if (result)
     return result;
   return_ISTRING_COMPARE (x->name, y->name);
-#else
-  return x->name == y->name ? 0 : -1;
-#endif
-}
+}
+#endif /* !CONFIG_WITH_STRCACHE2 */
 
 #ifndef	DIRFILE_BUCKETS
@@ -510,9 +489,10 @@
 #ifndef CONFIG_WITH_STRCACHE2
   dir_key.name = name;
+  dir_slot = (struct directory **) hash_find_slot (&directories, &dir_key);
 #else
   p = name + strlen (name);
   dir_key.name = strcache_add_len (name, p - name);
-#endif
-  dir_slot = (struct directory **) hash_find_slot (&directories, &dir_key);
+  dir_slot = (struct directory **) hash_find_slot_strcached (&directories, &dir_key);
+#endif
   dir = *dir_slot;
 
@@ -657,9 +637,15 @@
 		  if (buckets < DIRFILE_BUCKETS)
 		    buckets = DIRFILE_BUCKETS;
-		  hash_init (&dc->dirfiles, buckets,
-			     dirfile_hash_1, dirfile_hash_2, dirfile_hash_cmp);
-#else
+		  hash_init_strcached (&dc->dirfiles, buckets, &file_strcache,
+                                       offsetof (struct dirfile, name));
+#else
+# ifndef CONFIG_WITH_STRCACHE2
 		  hash_init (&dc->dirfiles, DIRFILE_BUCKETS,
 			     dirfile_hash_1, dirfile_hash_2, dirfile_hash_cmp);
+# else  /* CONFIG_WITH_STRCACHE2 */
+                  hash_init_strcached (&dc->dirfiles, DIRFILE_BUCKETS,
+                                       &file_strcache,
+                                       offsetof (struct dirfile, name));
+# endif /* CONFIG_WITH_STRCACHE2 */
 #endif
 		  /* Keep track of how many directories are open.  */
@@ -730,10 +716,11 @@
       dirfile_key.name = filename;
       dirfile_key.length = strlen (filename);
+      df = hash_find_item (&dir->dirfiles, &dirfile_key);
 #else  /* CONFIG_WITH_STRCACHE2 */
       dirfile_key.length = strlen (filename);
       dirfile_key.name = filename
         = strcache_add_len (filename, dirfile_key.length);
+      df = hash_find_item_strcached (&dir->dirfiles, &dirfile_key);
 #endif /* CONFIG_WITH_STRCACHE2 */
-      df = hash_find_item (&dir->dirfiles, &dirfile_key);
       if (df)
         return !df->impossible;
@@ -811,5 +798,5 @@
 /* bird: end */
           if (errno)
-            fatal (NILF, "INTERNAL: readdir(%p): %s (filename=%s)\n", dir, strerror (errno), filename);
+            fatal (NILF, "INTERNAL: readdir(%p): %s (filename=%s)\n", (void *)dir, strerror (errno), filename);
           break;
         }
@@ -829,9 +816,11 @@
 #ifndef CONFIG_WITH_STRCACHE2
       dirfile_key.name = d->d_name;
-#else
-      dirfile_key.name = strcache_add_len (d->d_name, len);
-#endif
       dirfile_key.length = len;
       dirfile_slot = (struct dirfile **) hash_find_slot (&dir->dirfiles, &dirfile_key);
+#else
+      dirfile_key.name = strcache_add_len (d->d_name, len);
+      dirfile_key.length = len;
+      dirfile_slot = (struct dirfile **) hash_find_slot_strcached (&dir->dirfiles, &dirfile_key);
+#endif
 #ifdef WINDOWS32
       /*
@@ -1028,6 +1017,11 @@
   if (dir->contents->dirfiles.ht_vec == 0)
     {
+#ifndef CONFIG_WITH_STRCACHE2
       hash_init (&dir->contents->dirfiles, DIRFILE_BUCKETS,
 		 dirfile_hash_1, dirfile_hash_2, dirfile_hash_cmp);
+#else  /* CONFIG_WITH_STRCACHE2 */
+      hash_init_strcached (&dir->contents->dirfiles, DIRFILE_BUCKETS,
+                           &file_strcache, offsetof (struct dirfile, name));
+#endif /* CONFIG_WITH_STRCACHE2 */
     }
 
@@ -1122,9 +1116,10 @@
   dirfile_key.name = filename;
   dirfile_key.length = strlen (filename);
+  dirfile = hash_find_item (&dir->dirfiles, &dirfile_key);
 #else
   dirfile_key.length = strlen (filename);
   dirfile_key.name = strcache_add_len (filename, dirfile_key.length);
-#endif
-  dirfile = hash_find_item (&dir->dirfiles, &dirfile_key);
+  dirfile = hash_find_item_strcached (&dir->dirfiles, &dirfile_key);
+#endif
   if (dirfile)
     return dirfile->impossible;
@@ -1398,6 +1393,11 @@
 hash_init_directories (void)
 {
+#ifndef CONFIG_WITH_STRCACHE2
   hash_init (&directories, DIRECTORY_BUCKETS,
 	     directory_hash_1, directory_hash_2, directory_hash_cmp);
+#else  /*  */
+  hash_init_strcached (&directories, DIRECTORY_BUCKETS, &file_strcache,
+                       offsetof (struct directory, name));
+#endif /*  */
   hash_init (&directory_contents, DIRECTORY_BUCKETS,
 	     directory_contents_hash_1, directory_contents_hash_2,
Index: trunk/src/kmk/file.c
===================================================================
--- trunk/src/kmk/file.c	(revision 1901)
+++ trunk/src/kmk/file.c	(revision 1902)
@@ -41,12 +41,9 @@
 /* Hash table of files the makefile knows how to make.  */
 
+#ifndef CONFIG_WITH_STRCACHE2
 static unsigned long
 file_hash_1 (const void *key)
 {
-#ifndef CONFIG_WITH_STRCACHE2
   return_ISTRING_HASH_1 (((struct file const *) key)->hname);
-#else  /* CONFIG_WITH_STRCACHE2 */
-  return strcache2_get_ptr_hash (&file_strcache, ((struct file const *) key)->hname);
-#endif /* CONFIG_WITH_STRCACHE2 */
 }
 
@@ -54,10 +51,7 @@
 file_hash_2 (const void *key)
 {
-#ifndef CONFIG_WITH_STRCACHE2
   return_ISTRING_HASH_2 (((struct file const *) key)->hname);
-#else  /* CONFIG_WITH_STRCACHE2 */
-  return strcache2_get_ptr_hash (&file_strcache, ((struct file const *) key)->hname);
-#endif /* CONFIG_WITH_STRCACHE2 */
-}
+}
+#endif /* !CONFIG_WITH_STRCACHE2 */
 
 static int
@@ -148,5 +142,5 @@
       file_key.hname = strcache2_lookup (&file_strcache, name, strlen (name));
       if (file_key.hname)
-        f = hash_find_item (&files, &file_key);
+        f = hash_find_item_strcached (&files, &file_key);
       else
         f = NULL;
@@ -155,5 +149,5 @@
     {
       file_key.hname = name;
-      f = hash_find_item (&files, &file_key);
+      f = hash_find_item_strcached (&files, &file_key);
     }
 
@@ -296,5 +290,9 @@
 
   /* Remove the "from" file from the hash.  */
+#ifndef CONFIG_WITH_STRCACHE2
   deleted_file = hash_delete (&files, from_file);
+#else
+  deleted_file = hash_delete_strcached (&files, from_file);
+#endif
   if (deleted_file != from_file)
     /* from_file isn't the one stored in files */
@@ -1343,8 +1341,18 @@
 init_hash_files (void)
 {
-#ifdef KMK
+#ifndef CONFIG_WITH_STRCACHE2
+# ifdef KMK
   hash_init (&files, /*65535*/ 32755, file_hash_1, file_hash_2, file_hash_cmp);
+# else
+  hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp);
+# endif
 #else
-  hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp);
+# ifdef KMK
+  hash_init_strcached (&files, 32755, &file_strcache,
+                       offsetof (struct file, hname));
+# else
+  hash_init_strcached (&files, 1000, &file_strcache,
+                       offsetof (struct file, hname));
+# endif
 #endif
 }
Index: trunk/src/kmk/hash.c
===================================================================
--- trunk/src/kmk/hash.c	(revision 1901)
+++ trunk/src/kmk/hash.c	(revision 1902)
@@ -19,4 +19,8 @@
 #include "make.h"
 #include "hash.h"
+#ifdef CONFIG_WITH_STRCACHE2
+# include <assert.h>
+#endif
+
 
 #define	CALLOC(t, n) ((t *) calloc (sizeof (t), (n)))
@@ -62,5 +66,28 @@
   ht->ht_hash_2 = hash_2;
   ht->ht_compare = hash_cmp;
-}
+#ifdef CONFIG_WITH_STRCACHE2
+  ht->ht_strcache = 0;
+  ht->ht_off_string = 0;
+#endif
+}
+
+#ifdef CONFIG_WITH_STRCACHE2
+/* Same as hash_init, except that no callbacks are needed since all
+   keys - including the ones being searched for - are from a string
+   cache.  This means that any give string will only have one pointer
+   value and that the hash and length can be retrived very cheaply,
+   thus permitting some nice optimizations.
+
+   STRCACHE points to the string cache, while OFF_STRING gives the
+   offset of the string pointer in the item structures the hash table
+   entries points to.  */
+void hash_init_strcached (struct hash_table *ht, unsigned long size,
+                          struct strcache2 *strcache, unsigned int off_string)
+{
+  hash_init (ht, size, 0, 0, 0);
+  ht->ht_strcache = strcache;
+  ht->ht_off_string = off_string;
+}
+#endif /* CONFIG_WITH_STRCACHE2 */
 
 /* Load an array of items into `ht'.  */
@@ -71,4 +98,5 @@
 {
   char *items = (char *) item_table;
+#ifndef CONFIG_WITH_STRCACHE2
   while (cardinality--)
     {
@@ -76,4 +104,18 @@
       items += size;
     }
+#else  /* CONFIG_WITH_STRCACHE2 */
+  if (ht->ht_strcache)
+    while (cardinality--)
+      {
+        hash_insert_strcached (ht, items);
+        items += size;
+      }
+  else
+    while (cardinality--)
+      {
+        hash_insert (ht, items);
+        items += size;
+      }
+#endif /* CONFIG_WITH_STRCACHE2 */
 }
 
@@ -90,4 +132,8 @@
   unsigned int hash_2 = 0;
   unsigned int hash_1 = (*ht->ht_hash_1) (key);
+
+#ifdef CONFIG_WITH_STRCACHE2
+  assert (ht->ht_strcache == 0);
+#endif
 
   ht->ht_lookups++;
@@ -124,16 +170,19 @@
 }
 
-#ifdef CONFIG_WITH_VALUE_LENGTH
-/* A variant of hash_find_slot that takes the hash values as arguments.
-   The HASH_2 argument is optional, pass 0 if not available.
-   Not having to call ht_hash_1 and perhaps also not ht_hash_2 does save
-   a whole bunch of cycles in some of the kBuild use cases (strcache sees
-   serious usage there). */
+#ifdef CONFIG_WITH_STRCACHE2
+/* hash_find_slot version for tables created with hash_init_strcached.  */
 void **
-hash_find_slot_prehashed (struct hash_table *ht, const void *key,
-                          unsigned int hash_1, unsigned int hash_2)
+hash_find_slot_strcached (struct hash_table *ht, const void *key)
 {
   void **slot;
   void **deleted_slot = 0;
+  const char *str1 = *(const char **)((const char *)key + ht->ht_off_string);
+  const char *str2;
+  unsigned int hash_1 = strcache2_get_ptr_hash (ht->ht_strcache, str1);
+  unsigned int hash_2;
+
+#ifdef CONFIG_WITH_STRCACHE2
+  assert (ht->ht_strcache != 0);
+#endif
 
   ht->ht_lookups++;
@@ -141,4 +190,29 @@
   make_stats_ht_lookups++;
 #endif
+
+  /* first iteration unrolled. */
+
+  hash_1 &= (ht->ht_size - 1);
+  slot = &ht->ht_vec[hash_1];
+  if (*slot == 0)
+    return slot;
+  if (*slot != hash_deleted_item)
+    {
+      str2 = *(const char **)((const char *)(*slot) + ht->ht_off_string);
+      if (str1 == str2)
+        return slot;
+
+      ht->ht_collisions++;
+#ifdef CONFIG_WITH_MAKE_STATS
+      make_stats_ht_collisions++;
+#endif
+    }
+  else
+    deleted_slot = slot;
+
+  /* the rest of the loop. */
+
+  hash_2 = strcache2_get_hash1 (ht->ht_strcache, str1) | 1;
+  hash_1 += hash_2;
   for (;;)
     {
@@ -155,8 +229,8 @@
       else
 	{
-	  if (key == *slot)
+          str2 = *(const char **)((const char *)(*slot) + ht->ht_off_string);
+          if (str1 == str2)
 	    return slot;
-	  if ((*ht->ht_compare) (key, *slot) == 0)
-	    return slot;
+
 	  ht->ht_collisions++;
 #ifdef CONFIG_WITH_MAKE_STATS
@@ -164,11 +238,9 @@
 #endif
 	}
-      if (!hash_2)
-	  hash_2 = (*ht->ht_hash_2) (key) | 1;
+
       hash_1 += hash_2;
     }
 }
-
-#endif /* CONFIG_WITH_VALUE_LENGTH */
+#endif /* CONFIG_WITH_STRCACHE2 */
 
 void *
@@ -178,4 +250,13 @@
   return ((HASH_VACANT (*slot)) ? 0 : *slot);
 }
+
+#ifdef CONFIG_WITH_STRCACHE2
+void *
+hash_find_item_strcached (struct hash_table *ht, const void *key)
+{
+  void **slot = hash_find_slot_strcached (ht, key);
+  return ((HASH_VACANT (*slot)) ? 0 : *slot);
+}
+#endif /* CONFIG_WITH_STRCACHE2 */
 
 void *
@@ -188,4 +269,15 @@
 }
 
+#ifdef CONFIG_WITH_STRCACHE2
+void *
+hash_insert_strcached (struct hash_table *ht, const void *item)
+{
+  void **slot = hash_find_slot_strcached (ht, item);
+  const void *old_item = slot ? *slot : 0;
+  hash_insert_at (ht, item, slot);
+  return (void *)((HASH_VACANT (old_item)) ? 0 : old_item);
+}
+#endif /* CONFIG_WITH_STRCACHE2 */
+
 void *
 hash_insert_at (struct hash_table *ht, const void *item, const void *slot)
@@ -203,4 +295,8 @@
     {
       hash_rehash (ht);
+#ifdef CONFIG_WITH_STRCACHE2
+      if (ht->ht_strcache)
+        return (void *)hash_find_slot_strcached (ht, item);
+#endif /* CONFIG_WITH_STRCACHE2 */
       return (void *) hash_find_slot (ht, item);
     }
@@ -215,4 +311,13 @@
   return hash_delete_at (ht, slot);
 }
+
+#ifdef CONFIG_WITH_STRCACHE2
+void *
+hash_delete_strcached (struct hash_table *ht, const void *item)
+{
+  void **slot = hash_find_slot_strcached (ht, item);
+  return hash_delete_at (ht, slot);
+}
+#endif /* CONFIG_WITH_STRCACHE2 */
 
 void *
@@ -353,4 +458,5 @@
   ht->ht_vec = (void **) CALLOC (struct token *, ht->ht_size);
 
+#ifndef CONFIG_WITH_STRCACHE2
   for (ovp = old_vec; ovp < &old_vec[old_ht_size]; ovp++)
     {
@@ -361,4 +467,24 @@
 	}
     }
+#else  /* CONFIG_WITH_STRCACHE2 */
+  if (ht->ht_strcache)
+    for (ovp = old_vec; ovp < &old_vec[old_ht_size]; ovp++)
+      {
+        if (! HASH_VACANT (*ovp))
+          {
+            void **slot = hash_find_slot_strcached (ht, *ovp);
+            *slot = *ovp;
+          }
+      }
+  else
+    for (ovp = old_vec; ovp < &old_vec[old_ht_size]; ovp++)
+      {
+        if (! HASH_VACANT (*ovp))
+          {
+            void **slot = hash_find_slot (ht, *ovp);
+            *slot = *ovp;
+          }
+      }
+#endif /* CONFIG_WITH_STRCACHE2 */
   ht->ht_empty_slots = ht->ht_size - ht->ht_fill;
   free (old_vec);
Index: trunk/src/kmk/hash.h
===================================================================
--- trunk/src/kmk/hash.h	(revision 1901)
+++ trunk/src/kmk/hash.h	(revision 1902)
@@ -54,4 +54,8 @@
   hash_func_t ht_hash_2;	/* secondary hash function */
   hash_cmp_func_t ht_compare;	/* comparison function */
+#ifdef CONFIG_WITH_STRCACHE2
+  struct strcache2 *ht_strcache; /* the string cache pointer. */
+  unsigned int ht_off_string;  /* offsetof (struct key, string) */
+#endif
 };
 
@@ -63,8 +67,4 @@
 		    unsigned long cardinality, unsigned long size));
 void **hash_find_slot __P((struct hash_table *ht, void const *key));
-#ifdef CONFIG_WITH_VALUE_LENGTH
-void **hash_find_slot_prehashed __P((struct hash_table *ht, const void *key,
-                                     unsigned int hash_1, unsigned int hash_2));
-#endif
 void *hash_find_item __P((struct hash_table *ht, void const *key));
 void *hash_insert __P((struct hash_table *ht, const void *item));
@@ -84,4 +84,13 @@
 void **hash_dump __P((struct hash_table *ht, void **vector_0, qsort_cmp_t compare));
 
+#ifdef CONFIG_WITH_STRCACHE2
+void hash_init_strcached __P((struct hash_table *ht, unsigned long size,
+                              struct strcache2 *strcache, unsigned int off_strptr));
+void **hash_find_slot_strcached __P((struct hash_table *ht, const void *key));
+void *hash_find_item_strcached __P((struct hash_table *ht, void const *key));
+void *hash_insert_strcached __P((struct hash_table *ht, const void *item));
+void *hash_delete_strcached __P((struct hash_table *ht, void const *item));
+#endif /* CONFIG_WITH_STRCACHE2 */
+
 extern void *hash_deleted_item;
 #define HASH_VACANT(item) ((item) == 0 || (void *) (item) == hash_deleted_item)
Index: trunk/src/kmk/variable.c
===================================================================
--- trunk/src/kmk/variable.c	(revision 1901)
+++ trunk/src/kmk/variable.c	(revision 1902)
@@ -110,14 +110,10 @@
 /* Hash table of all global variable definitions.  */
 
+#ifndef CONFIG_WITH_STRCACHE2
 static unsigned long
 variable_hash_1 (const void *keyv)
 {
   struct variable const *key = (struct variable const *) keyv;
-#ifndef CONFIG_WITH_STRCACHE2
   return_STRING_N_HASH_1 (key->name, key->length);
-#else
-  /* all requests are served from the cache. */
-  return strcache2_get_ptr_hash (&variable_strcache, key->name);
-#endif
 }
 
@@ -126,10 +122,5 @@
 {
   struct variable const *key = (struct variable const *) keyv;
-#ifndef CONFIG_WITH_STRCACHE2
   return_STRING_N_HASH_2 (key->name, key->length);
-#else
-  /* all requests are served from the cache. */
-  return strcache2_get_hash2 (&variable_strcache, key->name);
-#endif
 }
 
@@ -139,5 +130,4 @@
   struct variable const *x = (struct variable const *) xv;
   struct variable const *y = (struct variable const *) yv;
-#ifndef CONFIG_WITH_STRCACHE2
   int result = x->length - y->length;
   if (result)
@@ -145,10 +135,6 @@
 
   return_STRING_N_COMPARE (x->name, y->name, x->length);
-#else  /* CONFIG_WITH_STRCACHE2 */
-
-  /* everything is in the cache. */
-  return x->name == y->name ? 0 : -1;
-#endif /* CONFIG_WITH_STRCACHE2 */
-}
+}
+#endif /* !CONFIG_WITH_STRCACHE2 */
 
 #ifndef	VARIABLE_BUCKETS
@@ -185,9 +171,12 @@
 init_hash_global_variable_set (void)
 {
+#ifndef CONFIG_WITH_STRCACHE2
   hash_init (&global_variable_set.table, VARIABLE_BUCKETS,
 	     variable_hash_1, variable_hash_2, variable_hash_cmp);
-#ifdef CONFIG_WITH_STRCACHE2
+#else  /* CONFIG_WITH_STRCACHE2 */
   strcache2_init (&variable_strcache, "variable", 65536, 0, 0, 0);
-#endif
+  hash_init_strcached (&global_variable_set.table, VARIABLE_BUCKETS,
+                       &variable_strcache, offsetof (struct variable, name));
+#endif /* CONFIG_WITH_STRCACHE2 */
 }
 
@@ -236,5 +225,5 @@
       || !(v = strcache2_get_user_val (&variable_strcache, var_key.name)))
     {
-      var_slot = (struct variable **) hash_find_slot (&set->table, &var_key);
+      var_slot = (struct variable **) hash_find_slot_strcached (&set->table, &var_key);
       v = *var_slot;
     }
@@ -495,11 +484,17 @@
 
           if (v == 0)
+            {
+# ifndef NDEBUG
+              struct variable *v2 = (struct variable *) hash_find_item_strcached ((struct hash_table *) &setlist->set->table, &var_key);
+              assert (v2 == 0);
+# endif
               break;
+            }
           if ((void *)v != hash_deleted_item)
             {
-              if (variable_hash_cmp(&var_key, v) == 0)
+              if (v->name == cached_name)
                 {
 # ifndef NDEBUG
-                  struct variable *v2 = (struct variable *) hash_find_item ((struct hash_table *) &setlist->set->table, &var_key);
+                  struct variable *v2 = (struct variable *) hash_find_item_strcached ((struct hash_table *) &setlist->set->table, &var_key);
                   assert (v2 == v);
 # endif
@@ -509,8 +504,5 @@
             }
           if (!hash_2)
-            {
-              hash_2 = strcache2_get_hash2 (&variable_strcache, name);
-              assert (hash_2 & 1);
-            }
+            hash_2 = strcache2_get_hash1 (&variable_strcache, name) | 1;
           hash_1 += hash_2;
         }
@@ -520,5 +512,9 @@
       struct variable *v;
 
+# ifndef CONFIG_WITH_STRCACHE2
       v = (struct variable *) hash_find_item ((struct hash_table *) &set->table, &var_key);
+# else  /* CONFIG_WITH_STRCACHE2 */
+      v = (struct variable *) hash_find_item_strcached ((struct hash_table *) &set->table, &var_key);
+# endif /* CONFIG_WITH_STRCACHE2 */
       if (v)
 	return v->special ? handle_special_var (v) : v;
@@ -596,5 +592,10 @@
 {
   struct variable var_key;
-#ifdef CONFIG_WITH_STRCACHE2
+#ifndef CONFIG_WITH_STRCACHE2
+  var_key.name = (char *) name;
+  var_key.length = length;
+
+  return (struct variable *) hash_find_item ((struct hash_table *) &set->table, &var_key);
+#else  /* CONFIG_WITH_STRCACHE2 */
   const char *cached_name;
 
@@ -613,11 +614,10 @@
     }
 
-  name = cached_name;
+  var_key.name = cached_name;
+  var_key.length = length;
+
+  return (struct variable *) hash_find_item_strcached (
+    (struct hash_table *) &set->table, &var_key);
 #endif /* CONFIG_WITH_STRCACHE2 */
-
-  var_key.name = (char *) name;
-  var_key.length = length;
-
-  return (struct variable *) hash_find_item ((struct hash_table *) &set->table, &var_key);
 }
 
@@ -643,12 +643,17 @@
 	xmalloc (sizeof (struct variable_set_list));
       l->set = xmalloc (sizeof (struct variable_set));
-#else
+#else  /* CONFIG_WITH_ALLOC_CACHES */
       l = (struct variable_set_list *)
         alloccache_alloc (&variable_set_list_cache);
       l->set = (struct variable_set *)
         alloccache_alloc (&variable_set_cache);
-#endif
+#endif /* CONFIG_WITH_ALLOC_CACHES */
+#ifndef CONFIG_WITH_STRCACHE2
       hash_init (&l->set->table, PERFILE_VARIABLE_BUCKETS,
                  variable_hash_1, variable_hash_2, variable_hash_cmp);
+#else  /* CONFIG_WITH_STRCACHE2 */
+      hash_init_strcached (&l->set->table, PERFILE_VARIABLE_BUCKETS,
+                           &variable_strcache, offsetof (struct variable, name));
+#endif /* CONFIG_WITH_STRCACHE2 */
       file->variables = l;
     }
@@ -756,6 +761,11 @@
   set = (struct variable_set *) alloccache_alloc (&variable_set_cache);
 #endif
+#ifndef CONFIG_WITH_STRCACHE2
   hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS,
 	     variable_hash_1, variable_hash_2, variable_hash_cmp);
+#else  /* CONFIG_WITH_STRCACHE2 */
+  hash_init_strcached (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS,
+                       &variable_strcache, offsetof (struct variable, name));
+#endif /* CONFIG_WITH_STRCACHE2 */
 
 #ifndef CONFIG_WITH_ALLOC_CACHES
@@ -878,5 +888,10 @@
 	struct variable *from_var = *from_var_slot;
 	struct variable **to_var_slot
+#ifndef CONFIG_WITH_STRCACHE2
 	  = (struct variable **) hash_find_slot (&to_set->table, *from_var_slot);
+#else  /* CONFIG_WITH_STRCACHE2 */
+	  = (struct variable **) hash_find_slot_strcached (&to_set->table,
+                                                           *from_var_slot);
+#endif /* CONFIG_WITH_STRCACHE2 */
 	if (HASH_VACANT (*to_var_slot))
 	  hash_insert_at (&to_set->table, from_var, to_var_slot);
@@ -1296,6 +1311,11 @@
     set_list = file->variables;
 
+#ifndef CONFIG_WITH_STRCACHE2
   hash_init (&table, VARIABLE_BUCKETS,
 	     variable_hash_1, variable_hash_2, variable_hash_cmp);
+#else  /* CONFIG_WITH_STRCACHE2 */
+  hash_init_strcached (&table, VARIABLE_BUCKETS,
+                       &variable_strcache, offsetof (struct variable, name));
+#endif /* CONFIG_WITH_STRCACHE2 */
 
   /* Run through all the variable sets in the list,
@@ -1368,5 +1388,9 @@
 	      }
 
+#ifndef CONFIG_WITH_STRCACHE2
 	    new_slot = (struct variable **) hash_find_slot (&table, v);
+#else  /* CONFIG_WITH_STRCACHE2 */
+	    new_slot = (struct variable **) hash_find_slot_strcached (&table, v);
+#endif /* CONFIG_WITH_STRCACHE2 */
 	    if (HASH_VACANT (*new_slot))
 	      hash_insert_at (&table, v, new_slot);
@@ -1381,11 +1405,11 @@
   /* lookup the name in the string case, if it's not there it won't
      be in any of the sets either. */
-  cached_name = strcache2_lookup(&variable_strcache,
-                                 MAKELEVEL_NAME, MAKELEVEL_LENGTH);
+  cached_name = strcache2_lookup (&variable_strcache,
+                                  MAKELEVEL_NAME, MAKELEVEL_LENGTH);
   if (cached_name)
     {
       makelevel_key.name = cached_name;
       makelevel_key.length = MAKELEVEL_LENGTH;
-      hash_delete (&table, &makelevel_key);
+      hash_delete_strcached (&table, &makelevel_key);
     }
 #endif /* CONFIG_WITH_STRCACHE2 */
