Fossil

Check-in [233e9328]
Login

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

Overview
Comment:Simplification and optimization of the break_into_lines() helper routine in the diff logic. Use the strchr() routine from the standard library to help locate \n characters.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:233e9328ee639b3e9bdefd87c27e5d4a9fc86c79
User & Date: drh 2016-09-28 21:24:44
References
2016-09-29
11:59
Distinguish between a deleted file and a binary file in the side-by-side diff generator. Fix for a bug introduced by check-in [233e9328ee639b]. check-in: 1438be02 user: drh tags: trunk
Context
2016-09-28
23:47
In the random merge test (merge2.test) ignore cases where the parallel random edits overlap, resulting in a merge conflict. check-in: caea288c user: drh tags: trunk
21:24
Simplification and optimization of the break_into_lines() helper routine in the diff logic. Use the strchr() routine from the standard library to help locate \n characters. check-in: 233e9328 user: drh tags: trunk
20:26
Improved hash function for the diff algorithm. check-in: 173cca0d user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/diff.c.

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
200
201
202
203
204
205
206
207
208



209
210
211
212
213
214
215
*/
static DLine *break_into_lines(
  const char *z,
  int n,
  int *pnLine,
  u64 diffFlags
){
  int nLine, i, j, k, s, x;
  unsigned int h, h2;
  DLine *a;

  /* Count the number of lines.  Allocate space to hold
  ** the returned array.
  */
  for(i=j=0, nLine=1; i<n; i++, j++){
    if( z[i]<='\n' ){
      if( z[i]==0 ) return 0;
      if( z[i]=='\n' && z[i+1]!=0 ){
        nLine++;
        if( j>LENGTH_MASK ){
          return 0;
        }
        j = 0;
      }
    }
  }
  if( j>LENGTH_MASK ){
    return 0;
  }
  a = fossil_malloc( nLine*sizeof(a[0]) );
  memset(a, 0, nLine*sizeof(a[0]) );
  if( n==0 ){
    *pnLine = 0;
    return a;
  }

  /* Fill in the array */
  for(i=0; i<nLine; i++){
    for(j=0; z[j]>'\n' || (z[j]!=0 && z[j]!='\n'); j++){}
    a[i].z = z;
    k = j;
    if( diffFlags & DIFF_STRIP_EOLCR ){
      if( k>0 && z[k-1]=='\r' ){ k--; }
    }
    a[i].n = k;
    s = 0;
    if( diffFlags & DIFF_IGNORE_EOLWS ){
      while( k>0 && fossil_isspace(z[k-1]) ){ k--; }
................................................................................
      }
    }
    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 += j+1;
  }




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

/*







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<







 







|
<
>
>
>







135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168







169
170
171
172
173
174
175
...
193
194
195
196
197
198
199
200

201
202
203
204
205
206
207
208
209
210
*/
static DLine *break_into_lines(
  const char *z,
  int n,
  int *pnLine,
  u64 diffFlags
){
  int nLine, i, k, nn, s, x;
  unsigned int h, h2;
  DLine *a;
  const char *zNL, *z2;

  /* Early-out for the degenerate case */
  if( n==0 ) return 0;

  /* Count the number of lines in the input file.  Include the last line
  ** in the count even if it lacks the \n terminator
  */
  for(nLine=0, z2=z; (zNL = strchr(z2,'\n'))!=0; z2=zNL+1, nLine++){}
  if( z2[0]!=0 ) nLine++;

  a = fossil_malloc( sizeof(a[0])*nLine );
  memset(a, 0, sizeof(a[0])*nLine);
  i = 0;
  do{
    zNL = strchr(z,'\n');
    if( zNL==0 ) zNL = z+strlen(z);
    nn = (int)(zNL - z);
    if( nn>LENGTH_MASK ){
      fossil_free(a);
      return 0;
    }
    a[i].z = z;
    k = nn;







    if( diffFlags & DIFF_STRIP_EOLCR ){
      if( k>0 && z[k-1]=='\r' ){ k--; }
    }
    a[i].n = k;
    s = 0;
    if( diffFlags & DIFF_IGNORE_EOLWS ){
      while( k>0 && fossil_isspace(z[k-1]) ){ k--; }
................................................................................
      }
    }
    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;

    i++;
  }while( zNL[0] && zNL[1] );
  assert( i==nLine );

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

/*