[git commit] ping: code shrink
Denys Vlasenko
vda.linux at googlemail.com
Thu Jun 27 23:33:47 UTC 2013
commit: http://git.busybox.net/busybox/commit/?id=26a7e2ecbf76db06cf0754a0664eaa68e3cae53a
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master
function old new delta
unpack_tail 262 243 -19
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
networking/ping.c | 27 ++++++++++++++-------------
1 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/networking/ping.c b/networking/ping.c
index 8c08c80..f27e214 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -372,7 +372,7 @@ struct globals {
struct sockaddr_in6 sin6;
#endif
} pingaddr;
- char rcvd_tbl[MAX_DUP_CHK / 8];
+ unsigned char rcvd_tbl[MAX_DUP_CHK / 8];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define if_index (G.if_index )
@@ -402,13 +402,11 @@ void BUG_ping_globals_too_big(void);
} while (0)
-#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
-#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
-#define SET(bit) (A(bit) |= B(bit))
-#define CLR(bit) (A(bit) &= (~B(bit)))
-#define TST(bit) (A(bit) & B(bit))
-
-/**************************************************************************/
+#define BYTE(bit) rcvd_tbl[(bit)>>3]
+#define MASK(bit) (1 << ((bit) & 7))
+#define SET(bit) (BYTE(bit) |= MASK(bit))
+#define CLR(bit) (BYTE(bit) &= (~MASK(bit)))
+#define TST(bit) (BYTE(bit) & MASK(bit))
static void print_stats_and_exit(int junk) NORETURN;
static void print_stats_and_exit(int junk UNUSED_PARAM)
@@ -578,11 +576,10 @@ static void unpack_tail(int sz, uint32_t *tp,
const char *from_str,
uint16_t recv_seq, int ttl)
{
+ unsigned char *b, m;
const char *dupmsg = " (DUP!)";
unsigned triptime = triptime; /* for gcc */
- ++G.nreceived;
-
if (tp) {
/* (int32_t) cast is for hypothetical 64-bit unsigned */
/* (doesn't hurt 32-bit real-world anyway) */
@@ -594,11 +591,15 @@ static void unpack_tail(int sz, uint32_t *tp,
tmax = triptime;
}
- if (TST(recv_seq % MAX_DUP_CHK)) {
+ b = &BYTE(recv_seq % MAX_DUP_CHK);
+ m = MASK(recv_seq % MAX_DUP_CHK);
+ /*if TST(recv_seq % MAX_DUP_CHK):*/
+ if (*b & m) {
++G.nrepeats;
- --G.nreceived;
} else {
- SET(recv_seq % MAX_DUP_CHK);
+ /*SET(recv_seq % MAX_DUP_CHK):*/
+ *b |= m;
+ ++G.nreceived;
dupmsg += 7;
}
More information about the busybox-cvs
mailing list