summaryrefslogtreecommitdiffstats
path: root/mbbsd/read.c
diff options
context:
space:
mode:
authorkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-02-25 03:55:45 +0800
committerkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-02-25 03:55:45 +0800
commit2d27ba91cf281af58ed1a178593850ec09a3adc4 (patch)
treead5cb16a524612e70cac207e8cf4b5080ce73e10 /mbbsd/read.c
parent0f6facd7f1eeceb61d924b9e922d9c84706074bc (diff)
downloadpttbbs-2d27ba91cf281af58ed1a178593850ec09a3adc4.tar
pttbbs-2d27ba91cf281af58ed1a178593850ec09a3adc4.tar.gz
pttbbs-2d27ba91cf281af58ed1a178593850ec09a3adc4.tar.bz2
pttbbs-2d27ba91cf281af58ed1a178593850ec09a3adc4.tar.lz
pttbbs-2d27ba91cf281af58ed1a178593850ec09a3adc4.tar.xz
pttbbs-2d27ba91cf281af58ed1a178593850ec09a3adc4.tar.zst
pttbbs-2d27ba91cf281af58ed1a178593850ec09a3adc4.zip
dynamic allocate TagList[], save 2kb memory.
(only 0.2% online users use it) git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2540 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/read.c')
-rw-r--r--mbbsd/read.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/mbbsd/read.c b/mbbsd/read.c
index c127d4b0..f376ad2e 100644
--- a/mbbsd/read.c
+++ b/mbbsd/read.c
@@ -9,6 +9,7 @@ static int last_line; // PTT: last_line 游標可指的最後一個
/* ----------------------------------------------------- */
/* Tag List 標籤 */
/* ----------------------------------------------------- */
+static TagItem *TagList; /* ascending list */
/**
* @param locus
@@ -32,6 +33,10 @@ Tagger(time4_t chrono, int recno, int mode)
{
int head, tail, posi = 0, comp;
+ if(TagList == NULL) {
+ TagList = malloc(sizeof(TagItem)*MAXTAGS);
+ }
+
for (head = 0, tail = TagNum - 1, comp = 1; head <= tail;) {
posi = (head + tail) >> 1;
comp = TagList[posi].chrono - chrono;
@@ -58,15 +63,12 @@ Tagger(time4_t chrono, int recno, int mode)
memmove(&TagList[posi], &TagList[posi + 1],
(TagNum - posi) * sizeof(TagItem));
} else if (TagNum < MAXTAGS) {
- TagItem *tagp, buf[MAXTAGS];
+ TagItem *tagp;
- /* TODO memmove 即可, 不用另開 buf[] 再 memcpy 兩次 */
- tail = (TagNum - head) * sizeof(TagItem);
+ memmove(&TagList[head+1], &TagList[head], sizeof(TagItem)*(TagNum-head));
tagp = &TagList[head];
- memcpy(buf, tagp, tail);
tagp->chrono = chrono;
tagp->recno = recno;
- memcpy(++tagp, buf, tail);
TagNum++;
} else {
bell();
@@ -76,8 +78,8 @@ Tagger(time4_t chrono, int recno, int mode)
}
-void
-EnumTagName(char *fname, int locus)
+static void
+EnumTagName(char *fname, int locus) /* unused */
{
snprintf(fname, sizeof(fname), "M.%d.A", (int)TagList[locus].chrono);
}