From d70d894a99450058239d514a039f6cdb0ee5d1a0 Mon Sep 17 00:00:00 2001 From: Mike Frantzen Date: Sun, 19 Aug 2001 20:00:40 +0000 Subject: Quick optimization of pf_tree_key_compare (should half the instruction count) --- sys/net/pf.c | 35 ++++++++++++++--------------------- 1 file 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); } -- cgit v1.2.3