Changeset 0f15f12 for list.c


Ignore:
Timestamp:
Aug 20, 2009, 9:19:01 PM (12 years ago)
Author:
Anders Kaseorg <andersk@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
f278ff3
Parents:
5ebc202
git-author:
Anders Kaseorg <andersk@mit.edu> (08/20/09 21:14:37)
git-committer:
Anders Kaseorg <andersk@mit.edu> (08/20/09 21:19:01)
Message:
owl_list_grow, owl_dict_insert_element: Don’t use fuzzy math.

• Make sure to allocate at least as many elements as were requested.
• Don’t use floating point math to compute the expansion amount.
• In owl_dict_insert_element, reallocate using the right element size
  instead of relying on the GROWAT fudge factor (WTF?).

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • list.c

    r77bced3 r0f15f12  
    33
    44#define INITSIZE 10
    5 #define GROWBY 1.5
     5#define GROWBY 3 / 2
    66
    77int owl_list_create(owl_list *l)
     
    2525
    2626  if ((l->size+n) > l->avail) {
    27     ptr=owl_realloc(l->list, l->avail*GROWBY*sizeof(void *));
     27    int avail = MAX(l->avail * GROWBY, l->size + n);
     28    ptr = owl_realloc(l->list, avail * sizeof(void *));
    2829    if (ptr==NULL) abort();
    2930    l->list=ptr;
    30     l->avail=l->avail*GROWBY;
     31    l->avail = avail;
    3132  }
    3233
Note: See TracChangeset for help on using the changeset viewer.