diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2012-01-24 11:12:08 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2012-01-24 11:12:08 +0800 |
commit | d84d4798349b20cea993bb0fa451f9eb93fa19d2 (patch) | |
tree | 0554479bfaeb67ff47f4afa08c6fc2dba4c52a98 | |
parent | f29443e9ccc0e05f2ca9b52c9cb73ed89f9906a1 (diff) | |
download | pttbbs-d84d4798349b20cea993bb0fa451f9eb93fa19d2.tar pttbbs-d84d4798349b20cea993bb0fa451f9eb93fa19d2.tar.gz pttbbs-d84d4798349b20cea993bb0fa451f9eb93fa19d2.tar.bz2 pttbbs-d84d4798349b20cea993bb0fa451f9eb93fa19d2.tar.lz pttbbs-d84d4798349b20cea993bb0fa451f9eb93fa19d2.tar.xz pttbbs-d84d4798349b20cea993bb0fa451f9eb93fa19d2.tar.zst pttbbs-d84d4798349b20cea993bb0fa451f9eb93fa19d2.zip |
improve LIVE_ALLPOST implementation (faster comparison)
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5521 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/mbbsd/bbs.c | 34 |
1 files 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); |