From af017816e23956f9febad7fcae802ec5cc956c81 Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Thu, 14 May 2015 00:02:51 +1000 Subject: [PATCH] Use time_since() and time_until() instead of open-coded variants Use these helpers in the places where we're calling get_time() and comparing it against a single struct timeval. --- source/names.c | 7 +++---- source/parse.c | 4 +--- source/timer.c | 10 ++-------- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/source/names.c b/source/names.c index 6b7309f..7480f91 100644 --- a/source/names.c +++ b/source/names.c @@ -1847,7 +1847,7 @@ int in_join_list(char *chan, int server) void channel_sync(struct joinlist *tmp, char *channel) { - struct timeval tv; + double synch_time = time_since(&tmp->tv); if (tmp->gotinfo & GOTNEW) { @@ -1860,10 +1860,9 @@ void channel_sync(struct joinlist *tmp, char *channel) my_send_to_server(tmp->server, "MODE %s :%s", channel, chanmode); } - get_time(&tv); set_display_target(channel, LOG_CRAP); - if (do_hook(CHANNEL_SYNCH_LIST, "%s %1.3f", channel, BX_time_diff(tmp->tv,tv))) - bitchsay("Join to %s was synched in %1.3f secs!!", channel, BX_time_diff(tmp->tv,tv)); + if (do_hook(CHANNEL_SYNCH_LIST, "%s %1.3f", channel, synch_time)) + bitchsay("Join to %s was synched in %1.3f secs!!", channel, synch_time); #ifdef WANT_USERLIST delay_check_auto(channel); #endif diff --git a/source/parse.c b/source/parse.c index d690ce9..9fd730b 100644 --- a/source/parse.c +++ b/source/parse.c @@ -822,14 +822,12 @@ static void p_quit(char *from, char **ArgList) static int sping_reply(char *from, char *sping_dest, int server) { char buff[50]; - struct timeval timenow; Sping *tmp = get_server_sping(server, sping_dest); if (!tmp) return 0; - get_time(&timenow); - snprintf(buff, sizeof buff, "%2.4f", BX_time_diff(tmp->in_sping, timenow)); + snprintf(buff, sizeof buff, "%2.4f", time_since(&tmp->in_sping)); reset_display_target(); put_it("%s", convert_output_format("$G Server pong from %W$0%n $1 seconds", "%s %s", from, buff)); diff --git a/source/timer.c b/source/timer.c index 0107fb4..2b63ed2 100644 --- a/source/timer.c +++ b/source/timer.c @@ -457,7 +457,6 @@ char *function_timer(char *n, char *args) char *ref = next_arg(args, &args); TimerList *t = NULL; double time_left; - struct timeval current; if (ref && *ref) t = get_timer(ref); @@ -465,8 +464,7 @@ char *function_timer(char *n, char *args) if (!t) return m_strdup(empty_string); - get_time(¤t); - time_left = BX_time_diff(current, t->time); + time_left = time_until(&t->time); if (time_left < 0) time_left = 0.0; @@ -597,9 +595,6 @@ static char *schedule_timer (TimerList *ntimer) return ntimer->ref; } -static struct timeval current; - - /* * TimerTimeout: Called from irc_io to help create the timeout * part of the call to select. @@ -614,12 +609,11 @@ time_t TimerTimeout (void) ; else t = MAGIC_TIMEOUT; - get_time(¤t); if (!PendingTimers) timeout_in = tclTimerTimeout(MAGIC_TIMEOUT); else { - timeout_in = (time_t)(BX_time_diff(current, PendingTimers->time) * 1000); + timeout_in = (time_t)(time_until(&PendingTimers->time) * 1000); timeout_in = (time_t)(tclTimerTimeout((timeout_in < 0) ? 0 : timeout_in)); }