[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Make smartlist Do What Arma Expects.



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv1024/src/common

Modified Files:
	util.c util.h 
Log Message:
Make smartlist Do What Arma Expects.

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- util.c	30 Mar 2004 20:05:52 -0000	1.72
+++ util.c	30 Mar 2004 22:59:00 -0000	1.73
@@ -117,10 +117,11 @@
  * _add() adds an element, _remove() removes an element if it's there,
  * _choose() returns a random element.
  */
-smartlist_t *smartlist_create(int capacity) {
+#define SMARTLIST_DEFAULT_CAPACITY 32
+smartlist_t *smartlist_create() {
   smartlist_t *sl = tor_malloc(sizeof(smartlist_t));
   sl->num_used = 0;
-  sl->capacity = capacity;
+  sl->capacity = SMARTLIST_DEFAULT_CAPACITY;
   sl->list = tor_malloc(sizeof(void *) * sl->capacity);
   return sl;
 }
@@ -130,8 +131,8 @@
   free(sl);
 }
 
-void smartlist_grow_capacity(smartlist_t *sl, int n) {
-  if (sl->capacity < n) {
+void smartlist_set_capacity(smartlist_t *sl, int n) {
+  if (sl->capacity != n && sl->num_used < n) {
     sl->capacity = n;
     sl->list = tor_realloc(sl->list, sizeof(void*)*sl->capacity);
   }

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- util.h	30 Mar 2004 20:05:52 -0000	1.42
+++ util.h	30 Mar 2004 22:59:00 -0000	1.43
@@ -64,9 +64,9 @@
   int capacity;
 } smartlist_t;
 
-smartlist_t *smartlist_create(int capacity);
+smartlist_t *smartlist_create();
 void smartlist_free(smartlist_t *sl);
-void smartlist_grow_capacity(smartlist_t *sl, int n);
+void smartlist_set_capacity(smartlist_t *sl, int n);
 void smartlist_add(smartlist_t *sl, void *element);
 void smartlist_remove(smartlist_t *sl, void *element);
 int smartlist_isin(smartlist_t *sl, void *element);