diff options
author | ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-08-19 03:55:59 +0800 |
---|---|---|
committer | ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-08-19 03:55:59 +0800 |
commit | ef982e5c13120616dbfb32552d74deba348c27a1 (patch) | |
tree | c3e5571432de4f0baa04b8d69b379f7db340c2b7 /mbbsd | |
parent | 0c5a863ffc1fba8867bed7e2b49f82afa12fcd7b (diff) | |
download | pttbbs-ef982e5c13120616dbfb32552d74deba348c27a1.tar pttbbs-ef982e5c13120616dbfb32552d74deba348c27a1.tar.gz pttbbs-ef982e5c13120616dbfb32552d74deba348c27a1.tar.bz2 pttbbs-ef982e5c13120616dbfb32552d74deba348c27a1.tar.lz pttbbs-ef982e5c13120616dbfb32552d74deba348c27a1.tar.xz pttbbs-ef982e5c13120616dbfb32552d74deba348c27a1.tar.zst pttbbs-ef982e5c13120616dbfb32552d74deba348c27a1.zip |
get rid of linear search in getindex
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3065 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/read.c | 9 | ||||
-rw-r--r-- | mbbsd/record.c | 24 |
2 files changed, 5 insertions, 28 deletions
diff --git a/mbbsd/read.c b/mbbsd/read.c index 70579d49..f421f1f5 100644 --- a/mbbsd/read.c +++ b/mbbsd/read.c @@ -421,7 +421,7 @@ select_read(const keeploc_t * locmem, int sr_mode) char genbuf[MAXPATHLEN], *p = strstr(currdirect, "SR."); static int _mode = 0; int len, fd, fr, i, count=0, reference = 0, n_recommend = 0, - n_money=0; + n_money=0, diff; fileheader_t *fh = &headers[locmem->crs_ln - locmem->top_ln]; STATINC(STAT_SELECTREAD); @@ -497,9 +497,10 @@ select_read(const keeploc_t * locmem, int sr_mode) filetime = dasht(newdirect); count = dashs(newdirect) / sizeof(fileheader_t); - if( now - filetime > 180) + diff = now - filetime; + if( diff > 180) { - if( now - filetime > 3600) + if( diff > 3600) { len = O_CREAT | O_RDWR; count=0; @@ -511,7 +512,7 @@ select_read(const keeploc_t * locmem, int sr_mode) return READ_REDRAW; if( (fr = open(currdirect, O_RDONLY, 0)) != -1 ) { - if( now - filetime <= 3600) + if( diff <= 3600) { sprintf(fhs[0].filename, "X.%d", (int)filetime); len = - getindex(currdirect, &fhs[0], 0); diff --git a/mbbsd/record.c b/mbbsd/record.c index 5cb74cd4..f244876a 100644 --- a/mbbsd/record.c +++ b/mbbsd/record.c @@ -191,30 +191,6 @@ getindex(const char *direct, fileheader_t *fhdr, int end) close(fd); return -i; } - else{ - /* 上面的 binary search 爛掉了, 那就改用 linear search */ -#ifndef _BBS_UTIL_C_ - log_file("getindexerror", LOG_CREAT | LOG_VF, - "%s try to find: %d final i:%d\n", - direct, stamp, i); -#endif - // Ptt: log if there is still forever loop. - - end = get_num_records(direct, sizeof(fileheader_t)); - for( i = 1 ; i <= end ; ++i ){ - if( get_record_keep(direct, &fh, - sizeof(fileheader_t), i, &fd)==-1 ){ - if( fd != -1 ) - close(fd); - return 0; - } - if( atoi(fh.filename + 2) == stamp ){ - close(fd); - fhdr->multi.money = fh.multi.money; - return i; - } - } - } if( fd != -1 ) close(fd); return 0; |