mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 23:53:32 +01:00
Inline key smartlist functions; use fast versions by default.
svn:r5265
This commit is contained in:
parent
27fcbf87f3
commit
768160c872
@ -28,19 +28,6 @@ const char container_c_id[] = "$Id$";
|
|||||||
*/
|
*/
|
||||||
#define SMARTLIST_DEFAULT_CAPACITY 32
|
#define SMARTLIST_DEFAULT_CAPACITY 32
|
||||||
|
|
||||||
#ifndef FAST_SMARTLIST
|
|
||||||
/** A resizeable list of pointers, with associated helpful functionality. */
|
|
||||||
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
|
|
||||||
|
|
||||||
/** Allocate and return an empty smartlist.
|
/** Allocate and return an empty smartlist.
|
||||||
*/
|
*/
|
||||||
smartlist_t *
|
smartlist_t *
|
||||||
@ -236,36 +223,6 @@ smartlist_subtract(smartlist_t *sl1, const smartlist_t *sl2)
|
|||||||
smartlist_remove(sl1, sl2->list[i]);
|
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)
|
|
||||||
{
|
|
||||||
tor_assert(sl);
|
|
||||||
tor_assert(idx>=0);
|
|
||||||
tor_assert(idx < sl->num_used);
|
|
||||||
return sl->list[idx];
|
|
||||||
}
|
|
||||||
/** Change the value of the <b>idx</b>th element of sl to <b>val</b>.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
smartlist_set(smartlist_t *sl, int idx, void *val)
|
|
||||||
{
|
|
||||||
tor_assert(sl);
|
|
||||||
tor_assert(idx>=0);
|
|
||||||
tor_assert(idx < sl->num_used);
|
|
||||||
sl->list[idx] = val;
|
|
||||||
}
|
|
||||||
/** Return the number of items in sl.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
smartlist_len(const smartlist_t *sl)
|
|
||||||
{
|
|
||||||
return sl->num_used;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Remove the <b>idx</b>th element of sl; if idx is not the last
|
/** 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.
|
* 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.
|
* Return the old value of the <b>idx</b>th element.
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
#define __CONTAINER_H
|
#define __CONTAINER_H
|
||||||
#define CONTAINER_H_ID "$Id$"
|
#define CONTAINER_H_ID "$Id$"
|
||||||
|
|
||||||
/** Generic resizeable array. */
|
#import "compat.h"
|
||||||
typedef struct smartlist_t smartlist_t;
|
#import "util.h"
|
||||||
#ifdef FAST_SMARTLIST
|
|
||||||
|
|
||||||
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
|
/** <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> (\<=
|
* before it needs to be resized. Only the first <b>num_used</b> (\<=
|
||||||
* capacity) elements point to valid data.
|
* capacity) elements point to valid data.
|
||||||
@ -19,8 +19,7 @@ struct smartlist_t {
|
|||||||
void **list;
|
void **list;
|
||||||
int num_used;
|
int num_used;
|
||||||
int capacity;
|
int capacity;
|
||||||
};
|
} smartlist_t;
|
||||||
#endif
|
|
||||||
|
|
||||||
smartlist_t *smartlist_create(void);
|
smartlist_t *smartlist_create(void);
|
||||||
void smartlist_free(smartlist_t *sl);
|
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_intersect(smartlist_t *sl1, const smartlist_t *sl2);
|
||||||
void smartlist_subtract(smartlist_t *sl1, const smartlist_t *sl2);
|
void smartlist_subtract(smartlist_t *sl1, const smartlist_t *sl2);
|
||||||
/* smartlist_choose() is defined in crypto.[ch] */
|
/* smartlist_choose() is defined in crypto.[ch] */
|
||||||
#ifndef FAST_SMARTLIST
|
/** Return the number of items in sl.
|
||||||
void *smartlist_get(const smartlist_t *sl, int idx);
|
*/
|
||||||
void smartlist_set(smartlist_t *sl, int idx, void *val);
|
extern INLINE int smartlist_len(const smartlist_t *sl) {
|
||||||
int smartlist_len(const smartlist_t *sl);
|
#ifdef DEBUG_SMARTLIST
|
||||||
#else
|
tor_assert(sl);
|
||||||
#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)
|
|
||||||
#endif
|
#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(smartlist_t *sl, int idx);
|
||||||
void smartlist_del_keeporder(smartlist_t *sl, int idx);
|
void smartlist_del_keeporder(smartlist_t *sl, int idx);
|
||||||
void smartlist_insert(smartlist_t *sl, int idx, void *val);
|
void smartlist_insert(smartlist_t *sl, int idx, void *val);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "torint.h"
|
#include "torint.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#ifdef HAVE_SYS_TIME_H
|
#ifdef HAVE_SYS_TIME_H
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user