From 06a85177e980a326d1f5246cdcda926ed4bfbcde Mon Sep 17 00:00:00 2001 From: "Coren[m]" Date: Fri, 27 Sep 2013 18:33:52 +0200 Subject: [PATCH] minimalistic increase in elegance ;) DHT.c: - loops over assoc4/6 slightly more elegant --- toxcore/DHT.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 1c550628..c1eadc2a 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -1010,14 +1010,10 @@ static void get_bunchnodes(DHT *dht, Client_data *list, uint16_t length, uint16_ IPPTsPng *assoc; #ifdef CLIENT_ONETOONE_IP assoc = &list[i].assoc; - if (1) { #else uint32_t a; - for (a = 0; a < 2; a++) { - if (!a) - assoc = &list[i].assoc6; - else - assoc = &list[i].assoc4; + + for (a = 0, assoc = &list[i].assoc6; a < 2; a++, assoc = &list[i].assoc4) #endif if (ipport_isset(&(assoc->ip_port)) && !is_timeout(temp_time, assoc->ret_timestamp, BAD_NODE_TIMEOUT)) { @@ -1027,7 +1023,6 @@ static void get_bunchnodes(DHT *dht, Client_data *list, uint16_t length, uint16_ if (num >= max_num) return; } - } } } @@ -1105,20 +1100,15 @@ int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port) IPPTsPng *assoc = NULL; #ifdef CLIENT_ONETOONE_IP assoc = &client->assoc; - if (1) { #else uint32_t a; - for (a = 0; a < 2; a++) { - if (!a) - assoc = &client->assoc6; - else - assoc = &client->assoc4; + + for (a = 0, assoc = &client->assoc6; a < 2; a++, assoc = &client->assoc4) #endif if (!is_timeout(temp_time, assoc->timestamp, BAD_NODE_TIMEOUT)) { *ip_port = assoc->ip_port; return 1; } - } } } @@ -1145,14 +1135,10 @@ static void do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, uint8 IPPTsPng *assoc; #ifdef CLIENT_ONETOONE_IP assoc = &client->assoc; - if (1) { #else uint32_t a; - for (a = 0; a < 2; a++) { - if (!a) - assoc = &client->assoc6; - else - assoc = &client->assoc4; + + for (a = 0, assoc = &client->assoc6; a < 2; a++, assoc = &client->assoc4) #endif if (!is_timeout(temp_time, assoc->timestamp, KILL_NODE_TIMEOUT)) { @@ -1168,7 +1154,6 @@ static void do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, uint8 ++num_nodes; } } - } } if ((num_nodes != 0) &&