2010-04-29
2010-04-29 15:08:51 by Henrik Grubbström (Grubba) <grubba@grubba.org>
-
258a9284a6ea37432f2d043037fae30ed1e46924
(59 lines)
(+40/-19)
[
Show
| Annotate
]
Branch: 7.4
Changed HASH_PREFIX increment heuristic.
Backported from Pike 7.7.14.
Rev: src/stralloc.c:1.163
2:
|| This file is part of Pike. For copyright information see COPYRIGHT.
|| Pike is distributed under GPL, LGPL and MPL. See the file COPYING
|| for more information.
- || $Id: stralloc.c,v 1.162 2009/05/29 10:34:08 grubba Exp $
+ || $Id: stralloc.c,v 1.163 2010/04/29 15:08:51 grubba Exp $
*/
#include "global.h"
24:
#include <ctype.h>
#include <math.h>
- RCSID("$Id: stralloc.c,v 1.162 2009/05/29 10:34:08 grubba Exp $");
+ RCSID("$Id: stralloc.c,v 1.163 2010/04/29 15:08:51 grubba Exp $");
/* #define STRALLOC_USE_PRIMES */
80: Inside #if undefined(HASH_PREFIX)
/* Experimental dynamic hash length */
#ifndef HASH_PREFIX
static unsigned int HASH_PREFIX=64;
- static unsigned int need_more_hash_prefix=0;
+ static unsigned int need_more_hash_prefix_depth=0;
#endif
unsigned INT32 htable_size=0;
382:
return curr; /* pointer to string */
}
#ifndef HASH_PREFIX
+ if (curr->len > HASH_PREFIX)
depth++;
#endif
}
#ifndef HASH_PREFIX
/* These heuruistics might require tuning! /Hubbe */
- if((depth > HASH_PREFIX) && (HASH_PREFIX < (size_t)len))
+ if (depth > need_more_hash_prefix_depth)
{
- need_more_hash_prefix++;
- /* fprintf(stderr,"depth=%d num_strings=%d need_more_hash_prefix=%d HASH_PREFIX=%d\n",depth,num_strings,need_more_hash_prefix,HASH_PREFIX); */
- }else{
- if(need_more_hash_prefix)
- need_more_hash_prefix--;
+ #if 0
+ fprintf(stderr,
+ "depth=%d num_strings=%d need_more_hash_prefix_depth=%d\n"
+ " HASH_PREFIX=%d\n",
+ depth, num_strings, need_more_hash_prefix_depth,
+ HASH_PREFIX);
+ #endif /* 0 */
+ need_more_hash_prefix_depth = depth;
}
- #endif
+ #endif /* !HASH_PREFIX */
UNLOCK_BUCKET(hval);
return 0; /* not found */
}
495:
base_table=(struct pike_string **)xalloc(sizeof(struct pike_string *)*htable_size);
MEMSET((char *)base_table,0,sizeof(struct pike_string *)*htable_size);
+ need_more_hash_prefix_depth = 0;
+
for(h=0;h<old;h++)
rehash_string_backwards(old_base[h]);
513:
/* Use the BLOCK_ALLOC() stuff for short strings */
#define SHORT_STRING_BLOCK 256
- #define SHORT_STRING_THRESHOLD 15 /* % 4 === 1 */
+ #define SHORT_STRING_THRESHOLD 15 /* % 4 === -1 */
struct short_pike_string0 {
PIKE_STRING_CONTENTS;
594:
stralloc_rehash();
#ifndef HASH_PREFIX
- /* These heuruistics might require tuning! /Hubbe */
- if(need_more_hash_prefix > ( htable_size >> 4))
+ /* These heuristics might require tuning! /Hubbe */
+ if(need_more_hash_prefix_depth > MAX_AVG_LINK_LENGTH * 4)
{
- /* This could in theory have a pretty ugly complexity */
- /* /Hubbe
+ /* Changed heuristic 2005-01-17:
+ *
+ * Increase HASH_PREFIX if there's some bucket containing
+ * more than MAX_AVG_LINK_LENGTH * 4 strings that are longer
+ * than HASH_PREFIX.
+ * /grubba
*/
-
+ /* This could in theory have a pretty ugly complexity
+ * /Hubbe
+ */
+
#ifdef PIKE_RUN_UNLOCKED
mt_lock(bucket_locks);
- if(need_more_hash_prefix <= ( htable_size >> 4))
+ if(need_more_hash_prefix_depth <= MAX_AVG_LINK_DEPTH * 4)
{
/* Someone got here before us */
mt_lock(bucket_locks);
612: Inside #if undefined(HASH_PREFIX)
for(h=1;h<BUCKET_LOCKS;h++) mt_lock(bucket_locks+h);
#endif
- need_more_hash_prefix=0;
+ /* NOTE: No need to update to the corect value, since that will
+ * be done on demand.
+ */
+ need_more_hash_prefix_depth=0;
HASH_PREFIX=HASH_PREFIX*2;
- /* fprintf(stderr,"Doubling HASH_PREFIX to %d and rehashing\n",HASH_PREFIX); */
+ #if 0
+ fprintf(stderr, "Doubling HASH_PREFIX to %d and rehashing\n",
+ HASH_PREFIX);
+ #endif /* 0 */
for(h=0;h<htable_size;h++)
{