summaryrefslogtreecommitdiffstats
path: root/mbbsd/board.c
diff options
context:
space:
mode:
authorscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-02-27 15:19:14 +0800
committerscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-02-27 15:19:14 +0800
commit5115a2d27d53aa9e91b229aa4defdd2e63565712 (patch)
treef75e860142d4822d0c0e56d21caf1e86335bd66e /mbbsd/board.c
parent33da5f2c88e49d0ba8e7dadcb2695b3cf00a2306 (diff)
downloadpttbbs-5115a2d27d53aa9e91b229aa4defdd2e63565712.tar
pttbbs-5115a2d27d53aa9e91b229aa4defdd2e63565712.tar.gz
pttbbs-5115a2d27d53aa9e91b229aa4defdd2e63565712.tar.bz2
pttbbs-5115a2d27d53aa9e91b229aa4defdd2e63565712.tar.lz
pttbbs-5115a2d27d53aa9e91b229aa4defdd2e63565712.tar.xz
pttbbs-5115a2d27d53aa9e91b229aa4defdd2e63565712.tar.zst
pttbbs-5115a2d27d53aa9e91b229aa4defdd2e63565712.zip
Try to reduce calls on memmove.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1569 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/board.c')
-rw-r--r--mbbsd/board.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/mbbsd/board.c b/mbbsd/board.c
index e26b6c74..9821edc5 100644
--- a/mbbsd/board.c
+++ b/mbbsd/board.c
@@ -42,6 +42,8 @@ brc_putrecord(char *ptr, const char *name, int num, const int *list)
while (num > 1 && list[num - 1] < brc_expire_time)
num--; /* not to write the times before brc_expire_time */
+ if( num == 0 ) return ptr;
+
strncpy(ptr, name, BRC_STRLEN); /* write in board_name */
ptr += BRC_STRLEN;
*ptr++ = num; /* write in brc_num */
@@ -90,22 +92,29 @@ brc_insert_record(const char* board, int num, int* list)
/* put on the beginning */
ptr = brc_putrecord(tmp_buf, board, num, list);
new_size = (int)(ptr - tmp_buf);
- brc_size += new_size;
- if ( brc_size > BRC_MAXSIZE )
- brc_size = BRC_MAXSIZE;
- memmove(brc_buf + new_size, brc_buf, brc_size);
- memmove(brc_buf, tmp_buf, new_size);
+ if( new_size ){
+ brc_size += new_size;
+ if ( brc_size > BRC_MAXSIZE )
+ brc_size = BRC_MAXSIZE;
+ memmove(brc_buf + new_size, brc_buf, brc_size);
+ memmove(brc_buf, tmp_buf, new_size);
+ }
}else{
/* ptr points to the old current brc list.
* tmpp is the end of it (exclusive). */
+ end_size = endp - tmpp;
new_size = (int)(brc_putrecord(tmp_buf, board, num, list) - tmp_buf);
- brc_size += new_size - (tmpp - ptr);
- if ( brc_size > BRC_MAXSIZE )
- brc_size = BRC_MAXSIZE;
- end_size = brc_size - new_size - (ptr - brc_buf);
- if ( end_size )
- memmove(ptr + new_size, tmpp, end_size);
- memmove(ptr, tmp_buf, new_size);
+ if( new_size ){
+ brc_size += new_size - (tmpp - ptr);
+ if ( brc_size > BRC_MAXSIZE ){
+ end_size -= brc_size - BRC_MAXSIZE;
+ brc_size = BRC_MAXSIZE;
+ }
+ if ( end_size > 0 && ptr + new_size != tmpp )
+ memmove(ptr + new_size, tmpp, end_size);
+ memmove(ptr, tmp_buf, new_size);
+ }else
+ memmove(ptr, tmpp, brc_size - (tmpp - brc_buf));
}
brc_changed = 0;