[or-cvs] [tor/master] Simplify the math to round up to the next multiple of some value.
Nick Mathewson
nickm at seul.org
Mon Jul 13 20:51:48 UTC 2009
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Sat, 11 Jul 2009 00:44:27 +0200
Subject: Simplify the math to round up to the next multiple of some value.
Commit: d1437245c77b930382f9b36355a3fa67d48ecb38
---
src/or/geoip.c | 10 ----------
src/or/or.h | 10 ++++++++++
src/or/rephist.c | 22 ++++++++--------------
3 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/src/or/geoip.c b/src/or/geoip.c
index 13a6a28..aac4893 100644
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@ -461,16 +461,6 @@ _c_hist_compare(const void **_a, const void **_b)
* are willing to talk about it? */
#define GEOIP_MIN_OBSERVATION_TIME (12*60*60)
-/** Return the lowest x such that x is at least <b>number</b>, and x modulo
- * <b>divisor</b> == 0. */
-static INLINE unsigned
-round_to_next_multiple_of(unsigned number, unsigned divisor)
-{
- number += divisor - 1;
- number -= number % divisor;
- return number;
-}
-
/** Return a newly allocated comma-separated string containing entries for all
* the countries from which we've seen enough clients connect. The entry
* format is cc=num where num is the number of IPs we've seen connecting from
diff --git a/src/or/or.h b/src/or/or.h
index f298d53..be38035 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2669,6 +2669,16 @@ struct socks_request_t {
* every connection. */
};
+/** Return the lowest x such that x is at least <b>number</b>, and x modulo
+ * <b>divisor</b> == 0. */
+static INLINE unsigned
+round_to_next_multiple_of(unsigned number, unsigned divisor)
+{
+ number += divisor - 1;
+ number -= number % divisor;
+ return number;
+}
+
/* all the function prototypes go here */
/********************************* buffers.c ***************************/
diff --git a/src/or/rephist.c b/src/or/rephist.c
index ba363ba..73dd131 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -1404,10 +1404,8 @@ write_exit_stats(time_t when)
if (exit_bytes_read[i] + exit_bytes_written[i] > 0 &&
(total_bytes / (exit_bytes_read[i] + exit_bytes_written[i])
< EXIT_STATS_THRESHOLD)) {
- uint64_t num = b[i];
- num += EXIT_STATS_ROUND_UP_BYTES - 1;
- num /= EXIT_STATS_ROUND_UP_BYTES;
- num *= EXIT_STATS_ROUND_UP_BYTES;
+ uint64_t num = round_to_next_multiple_of(b[i],
+ EXIT_STATS_ROUND_UP_BYTES);
num /= 1024;
if (fprintf(out, "%s%d="U64_FORMAT,
comma++ ? "," : "", i,
@@ -1417,9 +1415,8 @@ write_exit_stats(time_t when)
other_bytes += b[i];
}
}
- other_bytes += EXIT_STATS_ROUND_UP_BYTES - 1;
- other_bytes /= EXIT_STATS_ROUND_UP_BYTES;
- other_bytes *= EXIT_STATS_ROUND_UP_BYTES;
+ other_bytes = round_to_next_multiple_of(other_bytes,
+ EXIT_STATS_ROUND_UP_BYTES);
other_bytes /= 1024;
if (fprintf(out, "%sother="U64_FORMAT"\n",
comma ? "," : "", other_bytes)<0)
@@ -1435,10 +1432,8 @@ write_exit_stats(time_t when)
if (exit_bytes_read[i] + exit_bytes_written[i] > 0 &&
(total_bytes / (exit_bytes_read[i] + exit_bytes_written[i])
< EXIT_STATS_THRESHOLD)) {
- uint32_t num = exit_streams[i];
- num += EXIT_STATS_ROUND_UP_STREAMS - 1;
- num /= EXIT_STATS_ROUND_UP_STREAMS;
- num *= EXIT_STATS_ROUND_UP_STREAMS;
+ uint32_t num = round_to_next_multiple_of(exit_streams[i],
+ EXIT_STATS_ROUND_UP_STREAMS);
if (fprintf(out, "%s%d=%d",
comma++ ? "," : "", i, num)<0)
goto done;
@@ -1446,9 +1441,8 @@ write_exit_stats(time_t when)
other_streams += exit_streams[i];
}
}
- other_streams += EXIT_STATS_ROUND_UP_STREAMS - 1;
- other_streams /= EXIT_STATS_ROUND_UP_STREAMS;
- other_streams *= EXIT_STATS_ROUND_UP_STREAMS;
+ other_streams = round_to_next_multiple_of(other_streams,
+ EXIT_STATS_ROUND_UP_STREAMS);
if (fprintf(out, "%sother=%d\n",
comma ? "," : "", other_streams)<0)
goto done;
--
1.5.6.5
More information about the tor-commits
mailing list