[or-cvs] Add a FAST_SMARTLIST define to optionally inline smartlist_...

Nick Mathewson nickm at seul.org
Fri Nov 12 20:41:55 UTC 2004


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

Modified Files:
	container.c container.h 
Log Message:
Add a FAST_SMARTLIST define to optionally inline smartlist_get and smartlist_len, which are two major profiling offenders.

Index: container.c
===================================================================
RCS file: /home/or/cvsroot/src/common/container.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- container.c	6 Nov 2004 05:18:29 -0000	1.4
+++ container.c	12 Nov 2004 20:41:52 -0000	1.5
@@ -23,6 +23,7 @@
  */
 #define SMARTLIST_DEFAULT_CAPACITY 32
 
+#ifndef FAST_SMARTLIST
 struct smartlist_t {
   /** <b>list</b> has enough capacity to store exactly <b>capacity</b> elements
    * before it needs to be resized.  Only the first <b>num_used</b> (\<=
@@ -32,6 +33,7 @@
   int num_used;
   int capacity;
 };
+#endif
 
 /** Allocate and return an empty smartlist.
  */
@@ -160,6 +162,7 @@
     smartlist_remove(sl1, sl2->list[i]);
 }
 
+#ifndef FAST_SMARTLIST
 /** Return the <b>idx</b>th element of sl.
  */
 void *smartlist_get(const smartlist_t *sl, int idx)
@@ -169,6 +172,14 @@
   tor_assert(idx < sl->num_used);
   return sl->list[idx];
 }
+/** Return the number of items in sl.
+ */
+int smartlist_len(const smartlist_t *sl)
+{
+  return sl->num_used;
+}
+#endif
+
 /** Change the value of the <b>idx</b>th element of sl to <b>val</b>; return the old
  * value of the <b>idx</b>th element.
  */
@@ -182,6 +193,7 @@
   sl->list[idx] = val;
   return old;
 }
+
 /** Remove the <b>idx</b>th element of sl; if idx is not the last
  * element, swap the last element of sl into the <b>idx</b>th space.
  * Return the old value of the <b>idx</b>th element.
@@ -212,12 +224,6 @@
     memmove(sl->list+idx, sl->list+idx+1, sizeof(void*)*(sl->num_used-idx));
   return old;
 }
-/** Return the number of items in sl.
- */
-int smartlist_len(const smartlist_t *sl)
-{
-  return sl->num_used;
-}
 /** Insert the value <b>val</b> as the new <b>idx</b>th element of
  * <b>sl</b>, moving all items previously at <b>idx</b> or later
  * forward one space.

Index: container.h
===================================================================
RCS file: /home/or/cvsroot/src/common/container.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- container.h	3 Nov 2004 18:28:00 -0000	1.3
+++ container.h	12 Nov 2004 20:41:52 -0000	1.4
@@ -7,6 +7,18 @@
 
 /** Generic resizeable array. */
 typedef struct smartlist_t smartlist_t;
+#ifdef FAST_SMARTLIST
+
+struct smartlist_t {
+  /** <b>list</b> has enough capacity to store exactly <b>capacity</b> elements
+   * before it needs to be resized.  Only the first <b>num_used</b> (\<=
+   * capacity) elements point to valid data.
+   */
+  void **list;
+  int num_used;
+  int capacity;
+};
+#endif
 
 smartlist_t *smartlist_create(void);
 void smartlist_free(smartlist_t *sl);
@@ -22,12 +34,18 @@
 void smartlist_intersect(smartlist_t *sl1, const smartlist_t *sl2);
 void smartlist_subtract(smartlist_t *sl1, const smartlist_t *sl2);
 /* smartlist_choose() is defined in crypto.[ch] */
+#ifndef FAST_SMARTLIST
 void *smartlist_get(const smartlist_t *sl, int idx);
+int smartlist_len(const smartlist_t *sl);
+#else
+#define smartlist_get(sl,idx) ((sl)->list[(idx)])
+#define smartlist_len(sl) ((sl)->num_used)
+#endif
 void *smartlist_set(smartlist_t *sl, int idx, void *val);
 void *smartlist_del(smartlist_t *sl, int idx);
 void *smartlist_del_keeporder(smartlist_t *sl, int idx);
 void smartlist_insert(smartlist_t *sl, int idx, void *val);
-int smartlist_len(const smartlist_t *sl);
+
 #define SPLIT_SKIP_SPACE   0x01
 #define SPLIT_IGNORE_BLANK 0x02
 int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep,



More information about the tor-commits mailing list