- always flush the IO write buffer when reading
[rsync/rsync.git] / match.c
diff --git a/match.c b/match.c
index bc759e2..333f0cf 100644 (file)
--- a/match.c
+++ b/match.c
@@ -100,12 +100,9 @@ static void matched(int f,struct sum_struct *s,struct map_struct *buf,
                rprintf(FINFO,"match at %d last_match=%d j=%d len=%d n=%d\n",
                        (int)offset,(int)last_match,i,(int)s->sums[i].len,(int)n);
 
-       send_token(f,i,buf,last_match,n,i==-1?0:s->sums[i].len);
+       send_token(f,i,buf,last_match,n,i<0?0:s->sums[i].len);
        data_transfer += n;
 
-       if (n > 0)
-               write_flush(f);
-
        if (i >= 0)
                n += s->sums[i].len;
   
@@ -212,7 +209,17 @@ static void hash_search(int f,struct sum_struct *s,
                } else {
                        --k;
                }
-               
+
+               /* By matching early we avoid re-reading the
+                  data 3 times in the case where a token
+                  match comes a long way after last
+                  match. The 3 reads are caused by the
+                  running match, the checksum update and the
+                  literal send. */
+               if (offset-last_match >= CHUNK_SIZE+s->n && 
+                   (end-offset > CHUNK_SIZE)) {
+                       matched(f,s,buf,offset - s->n, -2);
+               }
        } while (++offset < end);
        
        matched(f,s,buf,len,-1);