Fossil

Check-in [11e2c6e6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Further improve clarity.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | binDiffFix
Files: files | file ages | folders
SHA1:11e2c6e611d9caca1b21380fbfb86c568afc835a
User & Date: mistachkin 2016-10-03 23:18:30
Context
2016-10-03
23:23
Minor optimization. check-in: 9903ce5a user: mistachkin tags: binDiffFix
23:18
Further improve clarity. check-in: 11e2c6e6 user: mistachkin tags: binDiffFix
23:10
Another adjustment to handle some corner cases. check-in: 8017c358 user: mistachkin tags: binDiffFix
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/diff.c.

117
118
119
120
121
122
123
124


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
  int nTo;           /* Number of lines in aTo[] */
  int (*same_fn)(const DLine*,const DLine*); /* comparison function */
};

/*
** Count the number of lines in the input string.  Include the last line
** in the count even if it lacks the \n terminator.  If an empty string
** is specified, the number of lines is zero.


*/
static int count_lines(
  const char *z,
  int n
){
  int nLine;
  const char *zNL, *z2;
  for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){}
  if( z2[0]!=0 ) nLine++;
  return nLine;
}

/*
** Return an array of DLine objects containing a pointer to the
** start of each line and a hash of that line.  The lower
** bits of the hash store the length of each line.
................................................................................
){
  int nLine, i, k, nn, s, x;
  unsigned int h, h2;
  DLine *a;
  const char *zNL;

  nLine = count_lines(z, n);
  assert( nLine>0 || z[0]==0 );
  a = fossil_malloc( sizeof(a[0])*nLine );
  memset(a, 0, sizeof(a[0])*nLine);
  if( nLine==0 ){
    if( fossil_strchr(z,n,'\0')!=0 ){
      fossil_free(a);
      return 0;
    }
................................................................................
    if( diffFlags & DIFF_IGNORE_EOLWS ){
      while( k>0 && fossil_isspace(z[k-1]) ){ k--; }
    }
    if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
      int numws = 0;
      while( s<k && fossil_isspace(z[s]) ){ s++; }
      for(h=0, x=s; x<k; x++){
        if( z[x]==0 ){
          fossil_free(a);
          return 0;
        }
        if( fossil_isspace(z[x]) ){
          ++numws;
        }else{
          h += z[x];
          h *= 0x9e3779b1;
        }
      }
      k -= numws;
    }else{
      for(h=0, x=s; x<k; x++){
        if( z[x]==0 ){
          fossil_free(a);
          return 0;
        }
        h += z[x];
        h *= 0x9e3779b1;
      }
    }
................................................................................
    a[i].indent = s;
    a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
    h2 = h % nLine;
    a[i].iNext = a[h2].iHash;
    a[h2].iHash = i+1;
    z += nn+1; n -= nn+1;
    i++;
  }while( zNL[0] && zNL[1] );
  assert( i==nLine );

  /* Return results */
  *pnLine = nLine;
  return a;
}








|
>
>








|







 







|







 







|













|







 







|







117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
...
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
  int nTo;           /* Number of lines in aTo[] */
  int (*same_fn)(const DLine*,const DLine*); /* comparison function */
};

/*
** Count the number of lines in the input string.  Include the last line
** in the count even if it lacks the \n terminator.  If an empty string
** is specified, the number of lines is zero.  For the purposes of this
** function, a string is considered empty if it contains no characters
** -OR- it contains only NUL characters.
*/
static int count_lines(
  const char *z,
  int n
){
  int nLine;
  const char *zNL, *z2;
  for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){}
  if( z2[0]!='\0' ) nLine++;
  return nLine;
}

/*
** Return an array of DLine objects containing a pointer to the
** start of each line and a hash of that line.  The lower
** bits of the hash store the length of each line.
................................................................................
){
  int nLine, i, k, nn, s, x;
  unsigned int h, h2;
  DLine *a;
  const char *zNL;

  nLine = count_lines(z, n);
  assert( nLine>0 || z[0]=='\0' );
  a = fossil_malloc( sizeof(a[0])*nLine );
  memset(a, 0, sizeof(a[0])*nLine);
  if( nLine==0 ){
    if( fossil_strchr(z,n,'\0')!=0 ){
      fossil_free(a);
      return 0;
    }
................................................................................
    if( diffFlags & DIFF_IGNORE_EOLWS ){
      while( k>0 && fossil_isspace(z[k-1]) ){ k--; }
    }
    if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
      int numws = 0;
      while( s<k && fossil_isspace(z[s]) ){ s++; }
      for(h=0, x=s; x<k; x++){
        if( z[x]=='\0' ){
          fossil_free(a);
          return 0;
        }
        if( fossil_isspace(z[x]) ){
          ++numws;
        }else{
          h += z[x];
          h *= 0x9e3779b1;
        }
      }
      k -= numws;
    }else{
      for(h=0, x=s; x<k; x++){
        if( z[x]=='\0' ){
          fossil_free(a);
          return 0;
        }
        h += z[x];
        h *= 0x9e3779b1;
      }
    }
................................................................................
    a[i].indent = s;
    a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s);
    h2 = h % nLine;
    a[i].iNext = a[h2].iHash;
    a[h2].iHash = i+1;
    z += nn+1; n -= nn+1;
    i++;
  }while( zNL[0]!='\0' && zNL[1]!='\0' );
  assert( i==nLine );

  /* Return results */
  *pnLine = nLine;
  return a;
}