pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:8:   #include "pike_macros.h"   #include "dynamic_buffer.h"   #include "pike_macros.h"   #include "pike_memory.h"   #include "error.h"   #include "gc.h"   #include "stuff.h"      #define BEGIN_HASH_SIZE 997   #define MAX_AVG_LINK_LENGTH 3 + #define HASH_PREFIX 20      unsigned INT32 htable_size=0;   static unsigned int hashprimes_entry=0;   static struct pike_string **base_table=0;   static unsigned INT32 full_hash_value;   unsigned INT32 num_strings=0;      /*** Main string hash function ***/   static unsigned int StrHash(const char *s,int len)   { -  full_hash_value=hashmem((unsigned char *)s, len, 20); +  full_hash_value=hashmem((unsigned char *)s, len, HASH_PREFIX);    return full_hash_value % htable_size;   }         /*** find a string in the shared string table. ***/   static struct pike_string *internal_findstring(const char *s,int len,int h)   {    struct pike_string *curr,**prev, **base;       for(base = prev = base_table + h;( curr=*prev ); prev=&curr->next)
pike.git/src/stralloc.c:477:    unlink_pike_string(a);    return realloc_unlinked_string(a, size);    }else{    r=begin_shared_string(size);    MEMCPY(r->str, a->str, a->len);    free_string(a);    return r;    }   }    + /* Modify one index in a shared string +  * Not suitable for building new strings or changing multiple characters +  * within a string! +  */ + struct pike_string *modify_shared_string(struct pike_string *a, +  INT32 index, +  char c) + { + #ifdef DEBUG +  if(index<0 || index>=a->len) +  fatal("Index out of range in modify_shared_string()\n"); + #endif +  +  if(a->str[index]==c) return a; +  +  if(a->refs==1) +  { +  if(index>=HASH_PREFIX && index<a->len-8) +  { +  a->str[index]=c; +  return a; +  }else{ +  unlink_pike_string(a); +  a->str[index]=c; +  return end_shared_string(a); +  } +  }else{ +  struct pike_string *r; +  r=begin_shared_string(a->len); +  MEMCPY(r->str, a->str, a->len); +  a->str[index]=c; +  free_string(a); +  return end_shared_string(r); +  } + } +    /*** Add strings ***/   struct pike_string *add_shared_strings(struct pike_string *a,    struct pike_string *b)   {    INT32 size;    struct pike_string *ret;    char *buf;       size = a->len + b->len;