[BACK]Return to compat_ohash.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/compat_ohash.c between version 1.3 and 1.4

version 1.3, 2014/06/20 02:10:05 version 1.4, 2014/06/20 02:24:40
Line 29  int dummy;
Line 29  int dummy;
 #include <stdint.h>  #include <stdint.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   #include <limits.h>
 #include "compat_ohash.h"  #include "compat_ohash.h"
   
 struct _ohash_record {  struct _ohash_record {
Line 69  ohash_create_entry(struct ohash_info *i, const char *s
Line 70  ohash_create_entry(struct ohash_info *i, const char *s
 void  void
 ohash_delete(struct ohash *h)  ohash_delete(struct ohash *h)
 {  {
         (h->info.hfree)(h->t, sizeof(struct _ohash_record) * h->size,          (h->info.free)(h->t, h->info.data);
                 h->info.data);  
 #ifndef NDEBUG  #ifndef NDEBUG
         h->t = NULL;          h->t = NULL;
 #endif  #endif
Line 80  static void
Line 80  static void
 ohash_resize(struct ohash *h)  ohash_resize(struct ohash *h)
 {  {
         struct _ohash_record *n;          struct _ohash_record *n;
         unsigned int    ns, j;          size_t ns;
           unsigned int    j;
         unsigned int    i, incr;          unsigned int    i, incr;
   
         if (4 * h->deleted < h->total)          if (4 * h->deleted < h->total) {
                 ns = h->size << 1;                  if (h->size >= (UINT_MAX >> 1U))
         else if (3 * h->deleted > 2 * h->total)                          ns = UINT_MAX;
                 ns = h->size >> 1;                  else
                           ns = h->size << 1U;
           } else if (3 * h->deleted > 2 * h->total)
                   ns = h->size >> 1U;
         else          else
                 ns = h->size;                  ns = h->size;
         if (ns < MINSIZE)          if (ns < MINSIZE)
Line 95  ohash_resize(struct ohash *h)
Line 99  ohash_resize(struct ohash *h)
         STAT_HASH_EXPAND++;          STAT_HASH_EXPAND++;
         STAT_HASH_SIZE += ns - h->size;          STAT_HASH_SIZE += ns - h->size;
 #endif  #endif
         n = (h->info.halloc)(sizeof(struct _ohash_record) * ns, h->info.data);  
           n = (h->info.calloc)(ns, sizeof(struct _ohash_record), h->info.data);
         if (!n)          if (!n)
                 return;                  return;
   
Line 112  ohash_resize(struct ohash *h)
Line 117  ohash_resize(struct ohash *h)
                         n[i].p = h->t[j].p;                          n[i].p = h->t[j].p;
                 }                  }
         }          }
         (h->info.hfree)(h->t, sizeof(struct _ohash_record) * h->size,          (h->info.free)(h->t, h->info.data);
                 h->info.data);  
         h->t = n;          h->t = n;
         h->size = ns;          h->size = ns;
         h->total -= h->deleted;          h->total -= h->deleted;
Line 199  ohash_init(struct ohash *h, unsigned int size, struct 
Line 203  ohash_init(struct ohash *h, unsigned int size, struct 
 #endif  #endif
         /* Copy info so that caller may free it.  */          /* Copy info so that caller may free it.  */
         h->info.key_offset = info->key_offset;          h->info.key_offset = info->key_offset;
         h->info.halloc = info->halloc;          h->info.calloc = info->calloc;
         h->info.hfree = info->hfree;          h->info.free = info->free;
         h->info.alloc = info->alloc;          h->info.alloc = info->alloc;
         h->info.data = info->data;          h->info.data = info->data;
         h->t = (h->info.halloc)(sizeof(struct _ohash_record) * h->size,          h->t = (h->info.calloc)(h->size, sizeof(struct _ohash_record),
             h->info.data);                      h->info.data);
         h->total = h->deleted = 0;          h->total = h->deleted = 0;
 }  }
   

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

CVSweb