Parcourir la source

Iterate throught the htbl instead of building an array first.

master
Richard Nyberg il y a 15 ans
Parent
révision
a32db85e59
3 fichiers modifiés avec 22 ajouts et 14 suppressions
  1. +7
    -7
      btpd/cli_if.c
  2. +12
    -6
      btpd/tlib.c
  3. +3
    -1
      btpd/tlib.h

+ 7
- 7
btpd/cli_if.c Voir le fichier

@@ -189,16 +189,16 @@ cmd_tget(struct cli *cli, int argc, const char *args)
p = benc_dget_any(args, "from");
if (benc_isint(p)) {
enum ipc_twc from = benc_int(p, NULL);
struct tlib *tlv[tlib_count()];
tlib_put_all(tlv);
for (int i = 0; i < sizeof(tlv) / sizeof(tlv[0]); i++) {
if (!torrent_haunting(tlv[i]) && (
struct htbl_iter it;
struct tlib *tl;
for (tl = tlib_iter_first(&it); tl != NULL; tl = tlib_iter_next(&it)) {
if (!torrent_haunting(tl) && (
from == IPC_TWC_ALL ||
(!torrent_active(tlv[i]) && from == IPC_TWC_INACTIVE) ||
(torrent_active(tlv[i]) && from == IPC_TWC_ACTIVE))) {
(!torrent_active(tl) && from == IPC_TWC_INACTIVE) ||
(torrent_active(tl) && from == IPC_TWC_ACTIVE))) {
iobuf_swrite(&iob, "l");
for (int k = 0; k < nkeys; k++)
write_ans(&iob, tlv[i], opts[k]);
write_ans(&iob, tl, opts[k]);
iobuf_swrite(&iob, "e");
}
}


+ 12
- 6
btpd/tlib.c Voir le fichier

@@ -30,6 +30,18 @@ tlib_by_hash(const uint8_t *hash)
return hashtbl_find(m_hashtbl, hash);
}

struct tlib *
tlib_iter_first(struct htbl_iter *it)
{
return numtbl_iter_first(m_numtbl, it);
}

struct tlib *
tlib_iter_next(struct htbl_iter *it)
{
return numtbl_iter_next(it);
}

void
tlib_kill(struct tlib *tl)
{
@@ -295,12 +307,6 @@ id_hash(const void *k)
return dec_be32(k + 16);
}

void
tlib_put_all(struct tlib **v)
{
hashtbl_tov(m_hashtbl, v);
}

void
tlib_init(void)
{


+ 3
- 1
btpd/tlib.h Voir le fichier

@@ -22,7 +22,9 @@ struct file_time_size {
};

void tlib_init(void);
void tlib_put_all(struct tlib **v);

struct tlib *tlib_iter_first(struct htbl_iter *it);
struct tlib *tlib_iter_next(struct htbl_iter *it);

struct tlib *tlib_add(const uint8_t *hash, const char *mi, size_t mi_size,
const char *content, char *name);


Chargement…
Annuler
Enregistrer