From d84d4798349b20cea993bb0fa451f9eb93fa19d2 Mon Sep 17 00:00:00 2001 From: piaip Date: Tue, 24 Jan 2012 03:12:08 +0000 Subject: improve LIVE_ALLPOST implementation (faster comparison) git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5521 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index bce703a4..1ce0a44f 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -2263,22 +2263,32 @@ read_post(int ent, fileheader_t * fhdr, const char *direct) setdirpath(genbuf, direct, fhdr->filename); #if defined(BN_ALLPOST) && defined(USE_LIVE_ALLPOST) - if (strstr(genbuf, "/" BN_ALLPOST "/")) { + do { + static char allpost_base[PATHLEN] = ""; + static int allpost_base_len = 0; char bnbuf[IDLEN + 1] = ""; - const char *bn = strrchr(fhdr->title, '.'); + const char *bn; + int bnlen; - while (bn) { - int bnlen = strlen(++bn) - 2; - if (bnlen < 1 || bnlen > IDLEN) - break; - snprintf(bnbuf, sizeof(bnbuf), "%*.*s", bnlen, bnlen, bn); - setbfile(genbuf, bnbuf, fhdr->filename); + if (!*allpost_base) { + setbpath(allpost_base, BN_ALLPOST); + strlcat(allpost_base, "/", sizeof(allpost_base)); + allpost_base_len = strlen(allpost_base); + } + + if (!allpost_base_len) + break; + if (strncmp(allpost_base, genbuf, allpost_base_len) != 0) + break; + + bn = strrchr(fhdr->title, '.'); + bnlen = strlen(++bn) - 2; + snprintf(bnbuf, sizeof(bnbuf), "%*.*s", bnlen, bnlen, bn); + setbfile(genbuf, bnbuf, fhdr->filename); #ifdef DEBUG - vmsgf("redirect: %s", genbuf); + vmsgf("redirect: %s", genbuf); #endif - break; - } - } + } while (0); #endif more_result = more(genbuf, YEA); -- cgit v1.2.3