You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by jc...@apache.org on 2011/01/30 02:19:01 UTC

svn commit: r1065157 - /subversion/branches/diff-optimizations-bytes/subversion/libsvn_diff/diff_file.c

Author: jcorvel
Date: Sun Jan 30 01:19:01 2011
New Revision: 1065157

URL: http://svn.apache.org/viewvc?rev=1065157&view=rev
Log:
On the diff-optimizations-bytes branch:

More explicit handling of some edge conditions, when exiting datasources_open
early.

* subversion/libsvn_diff/diff_file.c
  (datasources_open): Make sure *prefix_lines is set to 0, so we have a
   correct value if we exit early.
   Initialize the files' suffix_start_chunks to -1, so as to make it easy to
   check for the suffix during the reading of tokens, even if the suffix
   scanning was not performed.
  (datasource_get_next_token): Simplify the check for encountering the suffix.

Modified:
    subversion/branches/diff-optimizations-bytes/subversion/libsvn_diff/diff_file.c

Modified: subversion/branches/diff-optimizations-bytes/subversion/libsvn_diff/diff_file.c
URL: http://svn.apache.org/viewvc/subversion/branches/diff-optimizations-bytes/subversion/libsvn_diff/diff_file.c?rev=1065157&r1=1065156&r2=1065157&view=diff
==============================================================================
--- subversion/branches/diff-optimizations-bytes/subversion/libsvn_diff/diff_file.c (original)
+++ subversion/branches/diff-optimizations-bytes/subversion/libsvn_diff/diff_file.c Sun Jan 30 01:19:01 2011
@@ -686,6 +686,10 @@ datasources_open(void *baton, apr_off_t 
   svn_boolean_t reached_one_eof;
   apr_size_t i;
 
+  /* Make sure prefix_lines is set correctly, even if we exit early because
+   * one of the files is empty. */
+  *prefix_lines = 0;
+
   /* Open datasources and read first chunk */
   for (i = 0; i < datasource_len; i++)
     {
@@ -702,6 +706,11 @@ datasources_open(void *baton, apr_off_t 
                          length[i], 0, file_baton->pool));
       file->endp = file->buffer + length[i];
       file->curp = file->buffer;
+      /* Set suffix_start_chunk to a guard value, so if suffix scanning is
+       * skipped because one of the files is empty, or because of
+       * reached_one_eof, we can still easily check for the suffix during
+       * token reading (datasource_get_next_token). */
+      file->suffix_start_chunk = -1;
 
       files[i] = *file;
     }
@@ -768,11 +777,12 @@ datasource_get_next_token(apr_uint32_t *
       return SVN_NO_ERROR;
     }
 
-  /* If identical suffix is defined, stop when we encounter it */
-  if (file->suffix_start_chunk || file->suffix_offset_in_chunk)
-    if (file->chunk == file->suffix_start_chunk
-        && (curp - file->buffer) == file->suffix_offset_in_chunk)
-      return SVN_NO_ERROR;
+  /* Stop when we encounter the identical suffix. If suffix scanning was not
+   * performed, suffix_start_chunk will be -1, so this condition will never
+   * be true. */
+  if (file->chunk == file->suffix_start_chunk
+      && curp - file->buffer == file->suffix_offset_in_chunk)
+    return SVN_NO_ERROR;
 
   /* Allocate a new token, or fetch one from the "reusable tokens" list. */
   file_token = file_baton->tokens;