From: terencehill Date: Sat, 5 Mar 2022 19:15:53 +0000 (+0100) Subject: Optimize process_time(2, x) to use half the number of strcat calls and compact code... X-Git-Tag: xonotic-v0.8.5~178 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1e2e1989141a0847be49445ea00c1914de25726e;p=xonotic%2Fxonotic-data.pk3dir.git Optimize process_time(2, x) to use half the number of strcat calls and compact code thanks to a macro --- diff --git a/qcsrc/lib/counting.qh b/qcsrc/lib/counting.qh index 58588971b..303ee6988 100644 --- a/qcsrc/lib/counting.qh +++ b/qcsrc/lib/counting.qh @@ -159,48 +159,17 @@ string process_time(float outputtype, int seconds) case 2: { string output = ""; - - if (tmp_seconds) - output = count_seconds(tmp_seconds); - - if (tmp_minutes) - { - output = strcat( - count_minutes(tmp_minutes), - ((output != "") ? strcat(", ", output) : "")); - } - - if (tmp_hours) - { - output = strcat( - count_hours(tmp_hours), - ((output != "") ? strcat(", ", output) : "")); - } - - if (tmp_days) - { - output = strcat( - count_days(tmp_days), - ((output != "") ? strcat(", ", output) : "")); - } - - if (tmp_weeks) - { - output = strcat( - count_weeks(tmp_weeks), - ((output != "") ? strcat(", ", output) : "")); - } - - if (tmp_years) - { - output = strcat( - count_years(tmp_years), - ((output != "") ? strcat(", ", output) : "")); - } - + #define APPEND_TIME(unit) \ + if (tmp_##unit) output = strcat(output, ((output != "") ? ", " : ""), count_##unit(tmp_##unit)) + APPEND_TIME(years); + APPEND_TIME(weeks); + APPEND_TIME(days); + APPEND_TIME(hours); + APPEND_TIME(minutes); + APPEND_TIME(seconds); + #undef APPEND_TIME if (output == "") return count_seconds(0); - return output; } case 3: