diff options
author | Mike Frantzen <frantzen@cvs.openbsd.org> | 2001-08-19 20:00:40 +0000 |
---|---|---|
committer | Mike Frantzen <frantzen@cvs.openbsd.org> | 2001-08-19 20:00:40 +0000 |
commit | d70d894a99450058239d514a039f6cdb0ee5d1a0 (patch) | |
tree | 832b915336e6ac1a89e1aa7139a332779bd364f2 | |
parent | cbbd6c725baf483541c88e797b527c4a244a6c74 (diff) |
Quick optimization of pf_tree_key_compare (should half the instruction count)
-rw-r--r-- | sys/net/pf.c | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/sys/net/pf.c b/sys/net/pf.c index 2411761a8a0..6f52aa4127d 100644 --- a/sys/net/pf.c +++ b/sys/net/pf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf.c,v 1.131 2001/08/19 19:46:08 dhartmei Exp $ */ +/* $OpenBSD: pf.c,v 1.132 2001/08/19 20:00:39 frantzen Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -200,30 +200,23 @@ int pf_normalize_tcp(int, struct ifnet *, struct mbuf *, int pf_tree_key_compare(struct pf_tree_key *a, struct pf_tree_key *b) { + register int diff; + /* * could use memcmp(), but with the best manual order, we can * minimize the number of average compares. what is faster? */ - if (a->proto < b->proto) - return (-1); - if (a->proto > b->proto) - return ( 1); - if (a->addr[0].s_addr < b->addr[0].s_addr) - return (-1); - if (a->addr[0].s_addr > b->addr[0].s_addr) - return ( 1); - if (a->addr[1].s_addr < b->addr[1].s_addr) - return (-1); - if (a->addr[1].s_addr > b->addr[1].s_addr) - return ( 1); - if (a->port[0] < b->port[0]) - return (-1); - if (a->port[0] > b->port[0]) - return ( 1); - if (a->port[1] < b->port[1]) - return (-1); - if (a->port[1] > b->port[1]) - return ( 1); + if ((diff = a->proto - b->proto) != 0) + return (diff); + if ((diff = a->addr[0].s_addr - b->addr[0].s_addr) != 0) + return (diff); + if ((diff = a->addr[1].s_addr - b->addr[1].s_addr) != 0) + return (diff); + if ((diff = a->port[0] - b->port[0]) != 0) + return (diff); + if ((diff = a->port[1] - b->port[1]) != 0) + return (diff); + return (0); } |