2005-11-30 [colin] 1.9.100cvs46
authorColin Leroy <colin@colino.net>
Wed, 30 Nov 2005 17:56:06 +0000 (17:56 +0000)
committerColin Leroy <colin@colino.net>
Wed, 30 Nov 2005 17:56:06 +0000 (17:56 +0000)
* src/matcher.c
* src/matcher.h
Optimize back yesterday's fix.

ChangeLog
PATCHSETS
configure.ac
src/matcher.c
src/matcher.h

index 90312d8390241030b3e9eb70591f105a08a028e2..55f648935f7d6a241ae579c66924dd8e8bf0822a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-11-30 [colin]     1.9.100cvs46
+
+       * src/matcher.c
+       * src/matcher.h
+               Optimize back yesterday's fix.
+
 2005-11-30 [paul]      1.9.100cvs45
 
        * manual/faq.xml
 2005-11-30 [paul]      1.9.100cvs45
 
        * manual/faq.xml
index 0113f7d005b3535f36e753cddac4b81f1b7853fb..f407e11683326cd2fe24030b5f174fc4d2c9f828 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.75.2.11 -r 1.75.2.12 src/matcher.c;  ) > 1.9.100cvs43.patchset
 ( cvs diff -u -r 1.75.2.12 -r 1.75.2.13 src/matcher.c;  ) > 1.9.100cvs44.patchset
 ( cvs diff -u -r 1.1.2.4 -r 1.1.2.5 manual/faq.xml;  cvs diff -u -r 1.1.2.1 -r 1.1.2.2 manual/intro.xml;  ) > 1.9.100cvs45.patchset
 ( cvs diff -u -r 1.75.2.11 -r 1.75.2.12 src/matcher.c;  ) > 1.9.100cvs43.patchset
 ( cvs diff -u -r 1.75.2.12 -r 1.75.2.13 src/matcher.c;  ) > 1.9.100cvs44.patchset
 ( cvs diff -u -r 1.1.2.4 -r 1.1.2.5 manual/faq.xml;  cvs diff -u -r 1.1.2.1 -r 1.1.2.2 manual/intro.xml;  ) > 1.9.100cvs45.patchset
+( cvs diff -u -r 1.75.2.13 -r 1.75.2.14 src/matcher.c;  cvs diff -u -r 1.39.2.5 -r 1.39.2.6 src/matcher.h;  ) > 1.9.100cvs46.patchset
index 809c367181da8de61c8967dad57bb3e2190490bf..a2f0671858991cc63a3d65eb9b2c500d8b4a9485 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=100
 INTERFACE_AGE=0
 BINARY_AGE=0
 MICRO_VERSION=100
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=45
+EXTRA_VERSION=46
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 35a11773279c2c6312ce727a2c656b4968337dd6..3c71b93703a0ace145e740dfc4bd2bfa9d1ef8c3 100644 (file)
@@ -675,10 +675,12 @@ static gboolean matcherlist_match_headers(MatcherList *matchers, FILE *fp)
        GSList *l;
        gchar buf[BUFFSIZE];
 
        GSList *l;
        gchar buf[BUFFSIZE];
 
-       for (l = matchers->matchers ; l != NULL ; l = g_slist_next(l)) {
-               MatcherProp *matcher = (MatcherProp *) l->data;
+       while (procheader_get_one_field(buf, sizeof(buf), fp, NULL) != -1) {
+               for (l = matchers->matchers ; l != NULL ; l = g_slist_next(l)) {
+                       MatcherProp *matcher = (MatcherProp *) l->data;
 
 
-               while (procheader_get_one_field(buf, sizeof(buf), fp, NULL) != -1) {
+                       if (matcher->done)
+                               continue;
 
                        /* if the criteria is ~headers_part or ~message, ZERO lines
                         * must NOT match for the rule to match. */
 
                        /* if the criteria is ~headers_part or ~message, ZERO lines
                         * must NOT match for the rule to match. */
@@ -686,10 +688,9 @@ static gboolean matcherlist_match_headers(MatcherList *matchers, FILE *fp)
                            matcher->criteria == MATCHCRITERIA_NOT_MESSAGE) {
                                if (matcherprop_match_one_header(matcher, buf)) {
                                        matcher->result = TRUE;
                            matcher->criteria == MATCHCRITERIA_NOT_MESSAGE) {
                                if (matcherprop_match_one_header(matcher, buf)) {
                                        matcher->result = TRUE;
-                                       continue; /* must check all lines */
                                } else {
                                        matcher->result = FALSE;
                                } else {
                                        matcher->result = FALSE;
-                                       break; /* no need to check more */
+                                       matcher->done = TRUE;
                                }
                        /* else, just one line matching is enough for the rule to match
                         */
                                }
                        /* else, just one line matching is enough for the rule to match
                         */
@@ -697,22 +698,17 @@ static gboolean matcherlist_match_headers(MatcherList *matchers, FILE *fp)
                                   matcherprop_criteria_message(matcher)){
                                if (matcherprop_match_one_header(matcher, buf)) {
                                        matcher->result = TRUE;
                                   matcherprop_criteria_message(matcher)){
                                if (matcherprop_match_one_header(matcher, buf)) {
                                        matcher->result = TRUE;
-                                       break; /* no need to check more */
+                                       matcher->done = TRUE;
                                }
                        }
                                }
                        }
-               }
-
-               /* if the rule matched and the matchers are OR, no need to
-                * check the others */
-               if (matcherprop_criteria_headers(matcher)) {
-                       if (matcher->result) {
+                       
+                       /* if the rule matched and the matchers are OR, no need to
+                        * check the others */
+                       if (matcher->result && matcher->done) {
                                if (!matchers->bool_and)
                                        return TRUE;
                        }
                }
                                if (!matchers->bool_and)
                                        return TRUE;
                        }
                }
-
-               /* go back to beginning of file */
-               rewind(fp);
        }
        return FALSE;
 }
        }
        return FALSE;
 }
@@ -771,41 +767,38 @@ static gboolean matcherlist_match_body(MatcherList *matchers, FILE *fp)
        GSList *l;
        gchar buf[BUFFSIZE];
        
        GSList *l;
        gchar buf[BUFFSIZE];
        
-       for (l = matchers->matchers ; l != NULL ; l = g_slist_next(l)) {
-               MatcherProp *matcher = (MatcherProp *) l->data;
-               
-               rewind(fp);
-               if (!matcherprop_criteria_message(matcher))
-                       matcherlist_skip_headers(fp);
-
-               while (fgets(buf, sizeof(buf), fp) != NULL) {
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
+               for (l = matchers->matchers ; l != NULL ; l = g_slist_next(l)) {
+                       MatcherProp *matcher = (MatcherProp *) l->data;
                        
                        
+                       if (matcher->done) 
+                               continue;
+
                        /* if the criteria is ~body_part or ~message, ZERO lines
                         * must NOT match for the rule to match. */
                        if (matcher->criteria == MATCHCRITERIA_NOT_BODY_PART ||
                            matcher->criteria == MATCHCRITERIA_NOT_MESSAGE) {
                                if (matcherprop_match_line(matcher, buf)) {
                                        matcher->result = TRUE;
                        /* if the criteria is ~body_part or ~message, ZERO lines
                         * must NOT match for the rule to match. */
                        if (matcher->criteria == MATCHCRITERIA_NOT_BODY_PART ||
                            matcher->criteria == MATCHCRITERIA_NOT_MESSAGE) {
                                if (matcherprop_match_line(matcher, buf)) {
                                        matcher->result = TRUE;
-                                       continue; /* must check all lines */
                                } else {
                                        matcher->result = FALSE;
                                } else {
                                        matcher->result = FALSE;
-                                       break; /* no need to check more */
+                                       matcher->done = TRUE;
                                }
                        /* else, just one line has to match */
                        } else if (matcherprop_criteria_body(matcher) ||
                                   matcherprop_criteria_message(matcher)) {
                                if (matcherprop_match_line(matcher, buf)) {
                                        matcher->result = TRUE;
                                }
                        /* else, just one line has to match */
                        } else if (matcherprop_criteria_body(matcher) ||
                                   matcherprop_criteria_message(matcher)) {
                                if (matcherprop_match_line(matcher, buf)) {
                                        matcher->result = TRUE;
-                                       break; /* no need to check more */
+                                       matcher->done = TRUE;
                                }
                        }
                                }
                        }
-               }
 
 
-               /* if the matchers are OR'ed and the rule matched,
-                * no need to check the others. */
-               if (matcher->result) {
-                       if (!matchers->bool_and)
-                               return TRUE;
+                       /* if the matchers are OR'ed and the rule matched,
+                        * no need to check the others. */
+                       if (matcher->result && matcher->done) {
+                               if (!matchers->bool_and)
+                                       return TRUE;
+                       }
                }
        }
        return FALSE;
                }
        }
        return FALSE;
@@ -845,6 +838,7 @@ gboolean matcherlist_match_file(MatcherList *matchers, MsgInfo *info,
                        read_body = TRUE;
                }
                matcher->result = FALSE;
                        read_body = TRUE;
                }
                matcher->result = FALSE;
+               matcher->done = FALSE;
        }
 
        if (!read_headers && !read_body)
        }
 
        if (!read_headers && !read_body)
@@ -865,6 +859,8 @@ gboolean matcherlist_match_file(MatcherList *matchers, MsgInfo *info,
        if (read_headers) {
                if (matcherlist_match_headers(matchers, fp))
                        read_body = FALSE;
        if (read_headers) {
                if (matcherlist_match_headers(matchers, fp))
                        read_body = FALSE;
+       } else {
+               matcherlist_skip_headers(fp);
        }
 
        /* read the body */
        }
 
        /* read the body */
index 563189c18a909cfba07584c0cbbab5cb3a3a50a0..329ad76c6ac4257a5cf889717e85fef076d3b2bb 100644 (file)
@@ -40,6 +40,7 @@ struct _MatcherProp {
        regex_t *preg;
        int error;
        gboolean result;
        regex_t *preg;
        int error;
        gboolean result;
+       gboolean done;
 };
 
 typedef struct _MatcherProp MatcherProp;
 };
 
 typedef struct _MatcherProp MatcherProp;