diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-10-05 09:03:12 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-10-05 09:03:12 +0800 |
commit | 3eced116f16e16fdf08c65c189ac7b2c1cd83232 (patch) | |
tree | f1d89dd97ce9a78c9b7034cd1d0d88f66183ef84 /mbbsd/stuff.c | |
parent | 2e0a596fcdfbb85c327cc2ede3648f10ef113d2b (diff) | |
download | pttbbs-3eced116f16e16fdf08c65c189ac7b2c1cd83232.tar pttbbs-3eced116f16e16fdf08c65c189ac7b2c1cd83232.tar.gz pttbbs-3eced116f16e16fdf08c65c189ac7b2c1cd83232.tar.bz2 pttbbs-3eced116f16e16fdf08c65c189ac7b2c1cd83232.tar.lz pttbbs-3eced116f16e16fdf08c65c189ac7b2c1cd83232.tar.xz pttbbs-3eced116f16e16fdf08c65c189ac7b2c1cd83232.tar.zst pttbbs-3eced116f16e16fdf08c65c189ac7b2c1cd83232.zip |
use bsearch in login_friend_online()
save cpu but increase SHM_t (sizeof(short) * MAX_ACTIVE) bytes
WARNING: SHM_t has been changed
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1212 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/stuff.c')
-rw-r--r-- | mbbsd/stuff.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index d8201330..a6aaec46 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -663,3 +663,28 @@ StringHash(unsigned char *s) } return (v * 2654435769UL) >> (32 - HASH_BITS); } + +inline int *intbsearch(int key, int *base0, int nmemb) +{ + /* 改自 /usr/src/lib/libc/stdlib/bsearch.c , + 專給搜 int array 用的, 不透過 compar function 故較快些 */ + const char *base = (char *)base0; + size_t lim; + int *p; + + for (lim = nmemb; lim != 0; lim >>= 1) { + p = (int *)(base + (lim >> 1) * 4); + if( key == *p ) + return p; + if( key > *p ){/* key > p: move right */ + base = (char *)p + 4; + lim--; + } /* else move left */ + } + return (NULL); +} + +int qsort_intcompar(const void *a, const void *b) +{ + return *(int *)a - *(int *)b; +} |