Branch: Tag:

2005-01-14

2005-01-14 14:27:43 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Backported rehash_string_backwards() fix from Pike 7.7.

Rev: src/stralloc.c:1.156

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.155 2004/05/18 08:13:15 grubba Exp $ + || $Id: stralloc.c,v 1.156 2005/01/14 14:27:43 grubba Exp $   */      #include "global.h"
24:   #include <ctype.h>   #include <math.h>    - RCSID("$Id: stralloc.c,v 1.155 2004/05/18 08:13:15 grubba Exp $"); + RCSID("$Id: stralloc.c,v 1.156 2005/01/14 14:27:43 grubba Exp $");      /* #define STRALLOC_USE_PRIMES */   
444:      static void rehash_string_backwards(struct pike_string *s)   { -  ptrdiff_t h; +  struct pike_string *prev = NULL; +  struct pike_string *next; +     if(!s) return; -  rehash_string_backwards(s->next); -  h = HMODULO(s->hval); -  s->next=base_table[h]; -  base_table[h]=s; +  +  /* Reverse the hash list. */ +  while ((next = s->next)) { +  s->next = prev; +  prev = s; +  s = next;    } -  +  s->next = prev;    -  +  /* Rehash the strings for this list. */ +  do { +  ptrdiff_t h = HMODULO(s->hval); +  next = s->next; +  s->next = base_table[h]; +  base_table[h] = s; +  } while ((s = next)); + } +    static void stralloc_rehash(void)   {    int h,old;