pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:1:   /*   || 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"   #include "stralloc.h"   #include "pike_macros.h"   #include "dynamic_buffer.h"   #include "pike_macros.h"   #include "pike_memory.h"   #include "pike_error.h"   #include "gc.h"
pike.git/src/stralloc.c:17:   #include "bignum.h"   #include "interpret.h"   #include "block_alloc.h"   #include "operators.h"      #include <errno.h>   #include <float.h>   #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 */      #ifdef STRALLOC_USE_PRIMES      #define SET_HSIZE(X) htable_size=hashprimes[(X)]   #define HMODULO(X) ((X) % htable_size)      #else   
pike.git/src/stralloc.c:73:   #define LOCK_BUCKET(HVAL)   #define UNLOCK_BUCKET(HVAL)   #endif      #define BEGIN_HASH_SIZE 997   #define MAX_AVG_LINK_LENGTH 3      /* 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;   static unsigned int hashprimes_entry=0;   static struct pike_string **base_table=0;   unsigned INT32 num_strings=0;   PMOD_EXPORT struct pike_string *empty_pike_string = 0;      /*** Main string hash function ***/   
pike.git/src/stralloc.c:375:    ( curr->str == s ||    !MEMCMP(curr->str, s,len<<size_shift))) /* found it */    {    *prev = curr->next;    curr->next = *base;    *base = curr;    UNLOCK_BUCKET(hval);    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 */   }      PMOD_EXPORT struct pike_string *binary_findstring(const char *foo, ptrdiff_t l)   {    return internal_findstring(foo, l, 0, StrHash(foo,l));   }      PMOD_EXPORT struct pike_string *findstring(const char *foo)
pike.git/src/stralloc.c:488: Inside #if defined(PIKE_RUN_UNLOCKED)
   * NOTE: bucket zero is already locked    */    for(h=1;h<BUCKET_LOCKS;h++) mt_lock(bucket_locks+h);   #endif       SET_HSIZE( ++hashprimes_entry );       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]);       if(old_base)    free((char *)old_base);      #ifdef PIKE_RUN_UNLOCKED    for(h=0;h<BUCKET_LOCKS;h++) mt_unlock(bucket_locks + h);   #endif   }      /* Allocation of strings */      /* Allocate some fixed string sizes with BLOCK_ALLOC. */      /* 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;    p_wchar0 str[SHORT_STRING_THRESHOLD+1];   };      struct short_pike_string1 {    PIKE_STRING_CONTENTS;    p_wchar1 str[SHORT_STRING_THRESHOLD+1];   };
pike.git/src/stralloc.c:587:    s->next = base_table[h];    base_table[h] = s;    s->hval=hval;    num_strings++;    UNLOCK_BUCKET(hval);       if(num_strings > MAX_AVG_LINK_LENGTH * htable_size)    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);    return;    }    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++)    {    struct pike_string *tmp=base_table[h];    base_table[h]=0;    while(tmp)    {    size_t h2;    struct pike_string *tmp2=tmp; /* First unlink */    tmp=tmp2->next;