[or-cvs] Remove maximum-size field from smartlists

Nick Mathewson nickm at seul.org
Tue Mar 30 20:05:54 UTC 2004


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

Modified Files:
	util.c util.h 
Log Message:
Remove maximum-size field from smartlists

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- util.c	30 Mar 2004 19:25:43 -0000	1.71
+++ util.c	30 Mar 2004 20:05:52 -0000	1.72
@@ -117,16 +117,10 @@
  * _add() adds an element, _remove() removes an element if it's there,
  * _choose() returns a random element.
  */
-#define SL_DEFAULT_CAPACITY 32
-
-smartlist_t *smartlist_create(int max_elements) {
+smartlist_t *smartlist_create(int capacity) {
   smartlist_t *sl = tor_malloc(sizeof(smartlist_t));
   sl->num_used = 0;
-  sl->max = max_elements;
-  if (max_elements <= SL_DEFAULT_CAPACITY)
-    sl->capacity = max_elements;
-  else
-    sl->capacity = SL_DEFAULT_CAPACITY;
+  sl->capacity = capacity;
   sl->list = tor_malloc(sizeof(void *) * sl->capacity);
   return sl;
 }
@@ -145,14 +139,11 @@
 
 /* add element to the list, but only if there's room */
 void smartlist_add(smartlist_t *sl, void *element) {
-  if (sl->num_used < sl->max) {
-    if (sl->num_used >= sl->capacity) {
-      sl->capacity *= 2;
-      sl->list = tor_realloc(sl->list, sizeof(void*)*sl->capacity);
-    }
-    sl->list[sl->num_used++] = element;
-  } else
-    log_fn(LOG_WARN,"We've already got %d elements, discarding.",sl->max);
+  if (sl->num_used >= sl->capacity) {
+    sl->capacity *= 2;
+    sl->list = tor_realloc(sl->list, sizeof(void*)*sl->capacity);
+  }
+  sl->list[sl->num_used++] = element;
 }
 
 void smartlist_remove(smartlist_t *sl, void *element) {

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- util.h	30 Mar 2004 19:25:43 -0000	1.41
+++ util.h	30 Mar 2004 20:05:52 -0000	1.42
@@ -61,11 +61,10 @@
 typedef struct {
   void **list;
   int num_used;
-  int max;
   int capacity;
 } smartlist_t;
 
-smartlist_t *smartlist_create(int max_elements);
+smartlist_t *smartlist_create(int capacity);
 void smartlist_free(smartlist_t *sl);
 void smartlist_grow_capacity(smartlist_t *sl, int n);
 void smartlist_add(smartlist_t *sl, void *element);



More information about the tor-commits mailing list