summaryrefslogtreecommitdiff
path: root/src/common/container.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-10-18 04:51:07 +0000
committerNick Mathewson <nickm@torproject.org>2005-10-18 04:51:07 +0000
commit768160c872da938d14b441fceef25de1d473df58 (patch)
tree4c8f725c4aa4876f75907220130690b3d001b376 /src/common/container.h
parent27fcbf87f3a11a033fdfb1e5e2a7f415b7125bdc (diff)
downloadtor-768160c872da938d14b441fceef25de1d473df58.tar.gz
tor-768160c872da938d14b441fceef25de1d473df58.zip
Inline key smartlist functions; use fast versions by default.
svn:r5265
Diffstat (limited to 'src/common/container.h')
-rw-r--r--src/common/container.h44
1 files changed, 30 insertions, 14 deletions
diff --git a/src/common/container.h b/src/common/container.h
index 56f5e35bf6..7a8ef78ad1 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -7,11 +7,11 @@
#define __CONTAINER_H
#define CONTAINER_H_ID "$Id$"
-/** Generic resizeable array. */
-typedef struct smartlist_t smartlist_t;
-#ifdef FAST_SMARTLIST
+#import "compat.h"
+#import "util.h"
-struct smartlist_t {
+/** A resizeable list of pointers, with associated helpful functionality. */
+typedef 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.
@@ -19,8 +19,7 @@ struct smartlist_t {
void **list;
int num_used;
int capacity;
-};
-#endif
+} smartlist_t;
smartlist_t *smartlist_create(void);
void smartlist_free(smartlist_t *sl);
@@ -38,15 +37,32 @@ int smartlist_overlap(const smartlist_t *sl1, const smartlist_t *sl2);
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);
-void smartlist_set(smartlist_t *sl, int idx, void *val);
-int smartlist_len(const smartlist_t *sl);
-#else
-#define smartlist_get(sl,idx) ((sl)->list[(idx)])
-#define smartlist_set(sl,idx,val) ((sl)->list[(idx)] = val)
-#define smartlist_len(sl) ((sl)->num_used)
+/** Return the number of items in sl.
+ */
+extern INLINE int smartlist_len(const smartlist_t *sl) {
+#ifdef DEBUG_SMARTLIST
+ tor_assert(sl);
+#endif
+ return (sl)->num_used;
+}
+/** Return the <b>idx</b>th element of sl.
+ */
+extern INLINE void *smartlist_get(const smartlist_t *sl, int idx) {
+#ifdef DEBUG_SMARTLIST
+ tor_assert(sl);
+ tor_assert(idx>=0);
+ tor_assert(sl->num_used < idx);
+#endif
+ return sl->list[idx];
+}
+extern INLINE void smartlist_set(smartlist_t *sl, int idx, void *val) {
+#ifdef DEBUG_SMARTLIST
+ tor_assert(sl);
+ tor_assert(idx>=0);
+ tor_assert(sl->num_used < idx);
#endif
+ sl->list[idx] = 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);