summaryrefslogtreecommitdiffstats
path: root/mbbsd/edit.c
diff options
context:
space:
mode:
authorvictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-01-15 15:27:12 +0800
committervictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-01-15 15:27:12 +0800
commit95476581c0bac0c784ce556002ff389444d02ba3 (patch)
tree3b3671250d9d1824bf9a4edbb8e3dabdd869882d /mbbsd/edit.c
parent3b1b5450c2b18864c063286376b99cbbaa76ec6a (diff)
downloadpttbbs-95476581c0bac0c784ce556002ff389444d02ba3.tar
pttbbs-95476581c0bac0c784ce556002ff389444d02ba3.tar.gz
pttbbs-95476581c0bac0c784ce556002ff389444d02ba3.tar.bz2
pttbbs-95476581c0bac0c784ce556002ff389444d02ba3.tar.lz
pttbbs-95476581c0bac0c784ce556002ff389444d02ba3.tar.xz
pttbbs-95476581c0bac0c784ce556002ff389444d02ba3.tar.zst
pttbbs-95476581c0bac0c784ce556002ff389444d02ba3.zip
edit.c: dont use such a lot of strlen()
mbbsd.c: update assess data before logout git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2401 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/edit.c')
-rw-r--r--mbbsd/edit.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/mbbsd/edit.c b/mbbsd/edit.c
index 1296f23d..d317d0c4 100644
--- a/mbbsd/edit.c
+++ b/mbbsd/edit.c
@@ -1354,22 +1354,23 @@ match_paren()
return;
type = (ptype - parens) / 2;
- parenum += ((ptype - parens) % 2) ? -1 : 1;
+ parenum = ((ptype - parens) % 2) ? -1 : 1;
- /* FIXME ¤Ó¦h strlen() */
/* FIXME CRASH */
if (parenum > 0) {
for (lino = currln, p = currline; p; p = p->next, lino++) {
- for (i = (lino == currln) ? currpnt + 1 : 0;
- (size_t)i < strlen(p->data); i++)
+ int len = strlen(p->data);
+ for (i = (lino == currln) ? currpnt + 1 : 0; i < len; i++) {
if (p->data[i] == '/' && p->data[++i] == '*') {
++i;
while (1) {
- while ((size_t)i < strlen(p->data) - 1 &&
- !(p->data[i] == '*' && p->data[i + 1] == '/'))
+ while (i < len &&
+ !(p->data[i] == '*' && p->data[i + 1] == '/')) {
i++;
- if ((size_t)i >= strlen(p->data) - 1 && p->next) {
+ }
+ if (i >= len && p->next) {
p = p->next;
+ len = strlen(p->data);
++lino;
i = 0;
} else
@@ -1377,13 +1378,15 @@ match_paren()
}
} else if ((c = p->data[i]) == '\'' || c == '"') {
while (1) {
- while (i < (int)(strlen(p->data) - 1))
- if (p->data[++i] == '\\' && (size_t)i < strlen(p->data) - 2)
+ while (i < len - 1) {
+ if (p->data[++i] == '\\' && (size_t)i < len - 2)
++i;
else if (p->data[i] == c)
goto end_quote;
- if ((size_t)i >= strlen(p->data) - 1 && p->next) {
+ }
+ if ((size_t)i >= len - 1 && p->next) {
p = p->next;
+ len = strlen(p->data);
++lino;
i = -1;
} else
@@ -1392,26 +1395,28 @@ match_paren()
end_quote:
;
} else if ((ptype = strchr(parens, p->data[i])) &&
- (ptype - parens) / 2 == type)
+ (ptype - parens) / 2 == type) {
if (!(parenum += ((ptype - parens) % 2) ? -1 : 1))
goto p_outscan;
+ }
+ }
}
} else {
- for (lino = currln, p = currline; p; p = p->prev, lino--)
- for (i = ((lino == currln) ?
- currpnt - 1 :
- (int)strlen(p->data) - 1);
- i >= 0; i--)
+ for (lino = currln, p = currline; p; p = p->prev, lino--) {
+ int len = strlen(p->data);
+ for (i = ((lino == currln) ? currpnt - 1 : len - 1); i >= 0; i--) {
if (p->data[i] == '/' && p->data[--i] == '*' && i > 0) {
--i;
while (1) {
while (i > 0 &&
- !(p->data[i] == '*' && p->data[i - 1] == '/'))
+ !(p->data[i] == '*' && p->data[i - 1] == '/')) {
i--;
+ }
if (i <= 0 && p->prev) {
p = p->prev;
+ len = strlen(p->data);
--lino;
- i = strlen(p->data) - 1;
+ i = len - 1;
} else
break;
}
@@ -1424,17 +1429,21 @@ match_paren()
goto begin_quote;
if (i <= 0 && p->prev) {
p = p->prev;
+ len = strlen(p->data);
--lino;
- i = strlen(p->data);
+ i = len;
} else
break;
}
- begin_quote:
+begin_quote:
;
} else if ((ptype = strchr(parens, p->data[i])) &&
- (ptype - parens) / 2 == type)
+ (ptype - parens) / 2 == type) {
if (!(parenum += ((ptype - parens) % 2) ? -1 : 1))
goto p_outscan;
+ }
+ }
+ }
}
p_outscan:
if (!parenum) {