From a04771ffc6435c1dc838e599a66f66fcc981b3ad Mon Sep 17 00:00:00 2001 From: kcwu Date: Sun, 24 May 2009 15:39:22 +0000 Subject: - optimize ip->desc lookup loop git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4475 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- daemon/fromd/ip_desc_db.c | 3 ++- mbbsd/mbbsd.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/daemon/fromd/ip_desc_db.c b/daemon/fromd/ip_desc_db.c index bd1b85d6..1870a9d3 100644 --- a/daemon/fromd/ip_desc_db.c +++ b/daemon/fromd/ip_desc_db.c @@ -91,9 +91,10 @@ int ip_desc_db_reload(const char * cfgfile) const char * ip_desc_db_lookup(const char * ip) { int i; + uint32_t ipaddr = htonl(ipstr2int(ip)); for (i = 0; i < db_len; i++) { - if (db[i].network == (htonl(ipstr2int(ip)) & db[i].netmask)) { + if (db[i].network == (ipaddr & db[i].netmask)) { return db[i].desc; } } diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 1deaee01..4ae920a4 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -924,9 +924,10 @@ static int where(const char *from) { int i; + uint32_t ipaddr = ipstr2int(from); for (i = 0; i < SHM->home_num; i++) { - if ((SHM->home_ip[i] & SHM->home_mask[i]) == (ipstr2int(from) & SHM->home_mask[i])) { + if ((SHM->home_ip[i] & SHM->home_mask[i]) == (ipaddr & SHM->home_mask[i])) { return i; } } -- cgit v1.2.3