pike.git / src / mapping.c

version» Context lines:

pike.git/src/mapping.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: mapping.c,v 1.161 2003/11/09 01:32:30 mast Exp $ + || $Id: mapping.c,v 1.162 2006/01/20 17:35:47 jonasw Exp $   */      #include "global.h" - RCSID("$Id: mapping.c,v 1.161 2003/11/09 01:32:30 mast Exp $"); + RCSID("$Id: mapping.c,v 1.162 2006/01/20 17:35:47 jonasw Exp $");   #include "main.h"   #include "object.h"   #include "mapping.h"   #include "svalue.h"   #include "array.h"   #include "pike_macros.h"   #include "pike_error.h"   #include "pike_memory.h"   #include "dynamic_buffer.h"   #include "interpret.h"
pike.git/src/mapping.c:266:   }      /* This function is used to rehash a mapping without loosing the internal    * order in each hash chain. This is to prevent mappings from becoming    * inefficient just after being rehashed.    */   static void mapping_rehash_backwards_evil(struct mapping_data *md,    struct keypair *from)   {    unsigned INT32 h; -  struct keypair *k; +  struct keypair *k, *prev = NULL, *next;    -  if(!from) return; -  mapping_rehash_backwards_evil(md,from->next); +  if(!(k = from)) return;    -  +  /* Reverse the hash chain. */ +  while ((next = k->next)) { +  k->next = prev; +  prev = k; +  k = next; +  } +  k->next = prev; +  +  from = k; +  +  /* Rehash and reverse the hash chain. */ +  while (from) {    /* unlink */    k=md->free_list;   #ifndef PIKE_MAPPING_KEYPAIR_LOOP   #ifdef PIKE_DEBUG    if(!k) Pike_fatal("Error in rehash: not enough keypairs.\n");   #endif    md->free_list=k->next;   #else /* PIKE_MAPPING_KEYPAIR_LOOP */    md->free_list++;   #endif /* !PIKE_MAPPING_KEYPAIR_LOOP */
pike.git/src/mapping.c:295:    /* link */    h=k->hval;    h%=md->hashsize;    k->next=md->hash[h];    md->hash[h]=k;       /* update */    md->ind_types |= 1<< (k->ind.type);    md->val_types |= 1<< (k->val.type);    md->size++; +  +  /* Reverse */ +  prev = from->next; +  from->next = next; +  next = from; +  from = prev;    } -  + }      static void mapping_rehash_backwards_good(struct mapping_data *md,    struct keypair *from)   {    unsigned INT32 h; -  struct keypair *k; +  struct keypair *k, *prev = NULL, *next;    -  if(!from) return; -  mapping_rehash_backwards_good(md,from->next); +  if(!(k = from)) return;    -  +  /* Reverse the hash chain. */ +  while ((next = k->next)) { +  k->next = prev; +  prev = k; +  k = next; +  } +  k->next = prev; +  +  from = k; +  +  /* Rehash and reverse the hash chain. */ +  while (from) {    /* unlink */    k=md->free_list;   #ifndef PIKE_MAPPING_KEYPAIR_LOOP   #ifdef PIKE_DEBUG    if(!k) Pike_fatal("Error in rehash: not enough keypairs.\n");   #endif    md->free_list=k->next;   #else /* PIKE_MAPPING_KEYPAIR_LOOP */    md->free_list++;   #endif /* !PIKE_MAPPING_KEYPAIR_LOOP */
pike.git/src/mapping.c:332:    /* link */    h=k->hval;    h%=md->hashsize;    k->next=md->hash[h];    md->hash[h]=k;       /* update */    md->ind_types |= 1<< (k->ind.type);    md->val_types |= 1<< (k->val.type);    md->size++; +  +  /* Reverse */ +  prev = from->next; +  from->next = next; +  next = from; +  from = prev;    } -  + }      /* This function re-allocates a mapping. It adjusts the max no. of    * values can be fitted into the mapping. It takes a bit of time to    * run, but is used seldom enough not to degrade preformance significantly.    */   static struct mapping *rehash(struct mapping *m, int new_size)   {    struct mapping_data *md, *new_md;   #ifdef PIKE_DEBUG    INT32 tmp=m->data->size;