Nobody was using the return values from smartlist_(set|del|del_keeporder), so remove them.

svn:r2823
This commit is contained in:
Nick Mathewson 2004-11-12 21:14:06 +00:00
parent 238a895e69
commit a8f9ba91db
3 changed files with 17 additions and 26 deletions

View File

@ -172,6 +172,16 @@ void *smartlist_get(const smartlist_t *sl, int idx)
tor_assert(idx < sl->num_used); tor_assert(idx < sl->num_used);
return sl->list[idx]; return sl->list[idx];
} }
/** 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.
*/
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. /** Return the number of items in sl.
*/ */
int smartlist_len(const smartlist_t *sl) int smartlist_len(const smartlist_t *sl)
@ -180,49 +190,29 @@ int smartlist_len(const smartlist_t *sl)
} }
#endif #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.
*/
void *smartlist_set(smartlist_t *sl, int idx, void *val)
{
void *old;
tor_assert(sl);
tor_assert(idx>=0);
tor_assert(idx < sl->num_used);
old = sl->list[idx];
sl->list[idx] = val;
return old;
}
/** 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.
*/ */
void *smartlist_del(smartlist_t *sl, int idx) void smartlist_del(smartlist_t *sl, int idx)
{ {
void *old;
tor_assert(sl); tor_assert(sl);
tor_assert(idx>=0); tor_assert(idx>=0);
tor_assert(idx < sl->num_used); tor_assert(idx < sl->num_used);
old = sl->list[idx];
sl->list[idx] = sl->list[--sl->num_used]; sl->list[idx] = sl->list[--sl->num_used];
return old;
} }
/** Remove the <b>idx</b>th element of sl; if idx is not the last element, /** Remove the <b>idx</b>th element of sl; if idx is not the last element,
* moving all subsequent elements back one space. Return the old value * moving all subsequent elements back one space. Return the old value
* of the <b>idx</b>th element. * of the <b>idx</b>th element.
*/ */
void *smartlist_del_keeporder(smartlist_t *sl, int idx) void smartlist_del_keeporder(smartlist_t *sl, int idx)
{ {
void *old;
tor_assert(sl); tor_assert(sl);
tor_assert(idx>=0); tor_assert(idx>=0);
tor_assert(idx < sl->num_used); tor_assert(idx < sl->num_used);
old = sl->list[idx];
--sl->num_used; --sl->num_used;
if (idx < sl->num_used) if (idx < sl->num_used)
memmove(sl->list+idx, sl->list+idx+1, sizeof(void*)*(sl->num_used-idx)); memmove(sl->list+idx, sl->list+idx+1, sizeof(void*)*(sl->num_used-idx));
return old;
} }
/** Insert the value <b>val</b> as the new <b>idx</b>th element of /** 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 * <b>sl</b>, moving all items previously at <b>idx</b> or later

View File

@ -36,14 +36,15 @@ 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 #ifndef FAST_SMARTLIST
void *smartlist_get(const smartlist_t *sl, int idx); 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); int smartlist_len(const smartlist_t *sl);
#else #else
#define smartlist_get(sl,idx) ((sl)->list[(idx)]) #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) #define smartlist_len(sl) ((sl)->num_used)
#endif #endif
void *smartlist_set(smartlist_t *sl, int idx, void *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);
#define SPLIT_SKIP_SPACE 0x01 #define SPLIT_SKIP_SPACE 0x01

View File

@ -545,7 +545,7 @@ test_util(void) {
smartlist_add(sl, (void*)2); smartlist_add(sl, (void*)2);
smartlist_add(sl, (void*)3); smartlist_add(sl, (void*)3);
smartlist_add(sl, (void*)4); smartlist_add(sl, (void*)4);
test_eq((void*)2, smartlist_del_keeporder(sl, 1)); smartlist_del_keeporder(sl, 1);
smartlist_insert(sl, 1, (void*)22); smartlist_insert(sl, 1, (void*)22);
smartlist_insert(sl, 0, (void*)0); smartlist_insert(sl, 0, (void*)0);
smartlist_insert(sl, 5, (void*)555); smartlist_insert(sl, 5, (void*)555);