Dash-rewriting optimized to be performed only after modification.
authorshort <>
Tue, 5 Dec 2000 15:54:13 +0000 (15:54 +0000)
committershort <>
Tue, 5 Dec 2000 15:54:13 +0000 (15:54 +0000)
 - saved only 7.5% on my current timelog

timeplan.c

index 61d71f9..357f9d0 100644 (file)
@@ -358,7 +358,7 @@ static char *modify(char *what)
 {
 regmatch_t matches[10];
 int i,m;
 {
 regmatch_t matches[10];
 int i,m;
-int doprep;
+int doprep,willprep;
 static char modbuf1[sizeof(buf)],modbuf2[sizeof(modbuf1)];
 char *src=what,*dstbase=modbuf1,*dst=dstbase;
 const char *start FAKEUSE,*end FAKEUSE,*patt;
 static char modbuf1[sizeof(buf)],modbuf2[sizeof(modbuf1)];
 char *src=what,*dstbase=modbuf1,*dst=dstbase;
 const char *start FAKEUSE,*end FAKEUSE,*patt;
@@ -366,10 +366,10 @@ const struct textlist *item;
 
        if (verbose) printf("modify: %s\n",what);
        modify_load();
 
        if (verbose) printf("modify: %s\n",what);
        modify_load();
-       for (m=0,item=modifies;;m++,item=item->next) {
+       for (m=0,item=modifies,willprep=1;;m++,item=item->next) {
 enum { PATT_START,PATT_MID,PATT_END,PATT_TERM } pattpos;
 
 enum { PATT_START,PATT_MID,PATT_END,PATT_TERM } pattpos;
 
-               for (doprep=1;doprep>=0;doprep--) {
+               for (doprep=willprep;doprep>=0;doprep--) {
                        if (doprep) {
                                *dst++='-';
                                for (patt=src;;patt++) {
                        if (doprep) {
                                *dst++='-';
                                for (patt=src;;patt++) {
@@ -384,12 +384,18 @@ enum { PATT_START,PATT_MID,PATT_END,PATT_TERM } pattpos;
                                        }
                                }
                        else {
                                        }
                                }
                        else {
+                               if (!item)
+                                       return src;
                                i=regexec(&modistructs[m].regex,src,LENGTH(matches),matches,0);
                                i=regexec(&modistructs[m].regex,src,LENGTH(matches),matches,0);
-                               if (i==REG_NOMATCH) continue;
+                               if (i==REG_NOMATCH) {
+                                       willprep=0;
+                                       break;
+                                       }
                                if (i) {
                                        fprintf(ERRH1"regexec() failed for \"%s\""ERRNO1,ERRH2,item->text,ERRNO2);
                                        exit(EXIT_FAILURE);
                                        }
                                if (i) {
                                        fprintf(ERRH1"regexec() failed for \"%s\""ERRNO1,ERRH2,item->text,ERRNO2);
                                        exit(EXIT_FAILURE);
                                        }
+                               willprep=1;
                                if (verbose) printf("matched: %s -> %s\n",item->text,modistructs[m].dst);
                                pattpos=PATT_START; patt=NULL;
                                while (pattpos!=PATT_TERM) {
                                if (verbose) printf("matched: %s -> %s\n",item->text,modistructs[m].dst);
                                pattpos=PATT_START; patt=NULL;
                                while (pattpos!=PATT_TERM) {
@@ -459,8 +465,6 @@ enum { PATT_START,PATT_MID,PATT_END,PATT_TERM } pattpos;
                                                 ||(src==modbuf2 && dstbase==modbuf1));
                                swap=src; src=dstbase; dst=dstbase=swap;
                                }
                                                 ||(src==modbuf2 && dstbase==modbuf1));
                                swap=src; src=dstbase; dst=dstbase=swap;
                                }
-                       if (!item)
-                               return src;
                        } /* for (doprep) */
                }
        /* NOTREACHED */
                        } /* for (doprep) */
                }
        /* NOTREACHED */