Mercurial > vim
comparison src/xdiff/xpatience.c @ 18802:3be01cf0a632 v8.1.2389
patch 8.1.2389: using old C style comments
Commit: https://github.com/vim/vim/commit/707d226ac58da752ecc6b7620055fb1df3957a27
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Dec 4 22:16:54 2019 +0100
patch 8.1.2389: using old C style comments
Problem: Using old C style comments.
Solution: Use // comments where appropriate.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 04 Dec 2019 22:30:07 +0100 |
parents | ef9f4be0bc5b |
children | d5142d87f898 |
comparison
equal
deleted
inserted
replaced
18801:484c63777038 | 18802:3be01cf0a632 |
---|---|
67 * If 1, this entry can serve as an anchor. See | 67 * If 1, this entry can serve as an anchor. See |
68 * Documentation/diff-options.txt for more information. | 68 * Documentation/diff-options.txt for more information. |
69 */ | 69 */ |
70 unsigned anchor : 1; | 70 unsigned anchor : 1; |
71 } *entries, *first, *last; | 71 } *entries, *first, *last; |
72 /* were common records found? */ | 72 // were common records found? |
73 unsigned long has_matches; | 73 unsigned long has_matches; |
74 mmfile_t *file1, *file2; | 74 mmfile_t *file1, *file2; |
75 xdfenv_t *env; | 75 xdfenv_t *env; |
76 xpparam_t const *xpp; | 76 xpparam_t const *xpp; |
77 }; | 77 }; |
84 return 1; | 84 return 1; |
85 } | 85 } |
86 return 0; | 86 return 0; |
87 } | 87 } |
88 | 88 |
89 /* The argument "pass" is 1 for the first file, 2 for the second. */ | 89 // The argument "pass" is 1 for the first file, 2 for the second. |
90 static void insert_record(xpparam_t const *xpp, int line, struct hashmap *map, | 90 static void insert_record(xpparam_t const *xpp, int line, struct hashmap *map, |
91 int pass) | 91 int pass) |
92 { | 92 { |
93 xrecord_t **records = pass == 1 ? | 93 xrecord_t **records = pass == 1 ? |
94 map->env->xdf1.recs : map->env->xdf2.recs; | 94 map->env->xdf1.recs : map->env->xdf2.recs; |
153 result->file1 = file1; | 153 result->file1 = file1; |
154 result->file2 = file2; | 154 result->file2 = file2; |
155 result->xpp = xpp; | 155 result->xpp = xpp; |
156 result->env = env; | 156 result->env = env; |
157 | 157 |
158 /* We know exactly how large we want the hash map */ | 158 // We know exactly how large we want the hash map |
159 result->alloc = count1 * 2; | 159 result->alloc = count1 * 2; |
160 result->entries = (struct entry *) | 160 result->entries = (struct entry *) |
161 xdl_malloc(result->alloc * sizeof(struct entry)); | 161 xdl_malloc(result->alloc * sizeof(struct entry)); |
162 if (!result->entries) | 162 if (!result->entries) |
163 return -1; | 163 return -1; |
164 memset(result->entries, 0, result->alloc * sizeof(struct entry)); | 164 memset(result->entries, 0, result->alloc * sizeof(struct entry)); |
165 | 165 |
166 /* First, fill with entries from the first file */ | 166 // First, fill with entries from the first file |
167 while (count1--) | 167 while (count1--) |
168 insert_record(xpp, line1++, result, 1); | 168 insert_record(xpp, line1++, result, 1); |
169 | 169 |
170 /* Then search for matches in the second file */ | 170 // Then search for matches in the second file |
171 while (count2--) | 171 while (count2--) |
172 insert_record(xpp, line2++, result, 2); | 172 insert_record(xpp, line2++, result, 2); |
173 | 173 |
174 return 0; | 174 return 0; |
175 } | 175 } |
183 { | 183 { |
184 int left = -1, right = longest; | 184 int left = -1, right = longest; |
185 | 185 |
186 while (left + 1 < right) { | 186 while (left + 1 < right) { |
187 int middle = left + (right - left) / 2; | 187 int middle = left + (right - left) / 2; |
188 /* by construction, no two entries can be equal */ | 188 // by construction, no two entries can be equal |
189 if (sequence[middle]->line2 > entry->line2) | 189 if (sequence[middle]->line2 > entry->line2) |
190 right = middle; | 190 right = middle; |
191 else | 191 else |
192 left = middle; | 192 left = middle; |
193 } | 193 } |
194 /* return the index in "sequence", _not_ the sequence length */ | 194 // return the index in "sequence", _not_ the sequence length |
195 return left; | 195 return left; |
196 } | 196 } |
197 | 197 |
198 /* | 198 /* |
199 * The idea is to start with the list of common unique lines sorted by | 199 * The idea is to start with the list of common unique lines sorted by |
214 * Therefore, overriding entries before this has no effect, so | 214 * Therefore, overriding entries before this has no effect, so |
215 * do not do that either. | 215 * do not do that either. |
216 */ | 216 */ |
217 int anchor_i = -1; | 217 int anchor_i = -1; |
218 | 218 |
219 /* Added to silence Coverity. */ | 219 // Added to silence Coverity. |
220 if (sequence == NULL) | 220 if (sequence == NULL) |
221 return map->first; | 221 return map->first; |
222 | 222 |
223 for (entry = map->first; entry; entry = entry->next) { | 223 for (entry = map->first; entry; entry = entry->next) { |
224 if (!entry->line2 || entry->line2 == NON_UNIQUE) | 224 if (!entry->line2 || entry->line2 == NON_UNIQUE) |
235 } else if (i == longest) { | 235 } else if (i == longest) { |
236 longest++; | 236 longest++; |
237 } | 237 } |
238 } | 238 } |
239 | 239 |
240 /* No common unique lines were found */ | 240 // No common unique lines were found |
241 if (!longest) { | 241 if (!longest) { |
242 xdl_free(sequence); | 242 xdl_free(sequence); |
243 return NULL; | 243 return NULL; |
244 } | 244 } |
245 | 245 |
246 /* Iterate starting at the last element, adjusting the "next" members */ | 246 // Iterate starting at the last element, adjusting the "next" members |
247 entry = sequence[longest - 1]; | 247 entry = sequence[longest - 1]; |
248 entry->next = NULL; | 248 entry->next = NULL; |
249 while (entry->previous) { | 249 while (entry->previous) { |
250 entry->previous->next = entry; | 250 entry->previous->next = entry; |
251 entry = entry->previous; | 251 entry = entry->previous; |
271 { | 271 { |
272 int end1 = line1 + count1, end2 = line2 + count2; | 272 int end1 = line1 + count1, end2 = line2 + count2; |
273 int next1, next2; | 273 int next1, next2; |
274 | 274 |
275 for (;;) { | 275 for (;;) { |
276 /* Try to grow the line ranges of common lines */ | 276 // Try to grow the line ranges of common lines |
277 if (first) { | 277 if (first) { |
278 next1 = first->line1; | 278 next1 = first->line1; |
279 next2 = first->line2; | 279 next2 = first->line2; |
280 while (next1 > line1 && next2 > line2 && | 280 while (next1 > line1 && next2 > line2 && |
281 match(map, next1 - 1, next2 - 1)) { | 281 match(map, next1 - 1, next2 - 1)) { |
290 match(map, line1, line2)) { | 290 match(map, line1, line2)) { |
291 line1++; | 291 line1++; |
292 line2++; | 292 line2++; |
293 } | 293 } |
294 | 294 |
295 /* Recurse */ | 295 // Recurse |
296 if (next1 > line1 || next2 > line2) { | 296 if (next1 > line1 || next2 > line2) { |
297 struct hashmap submap; | 297 struct hashmap submap; |
298 | 298 |
299 memset(&submap, 0, sizeof(submap)); | 299 memset(&submap, 0, sizeof(submap)); |
300 if (patience_diff(map->file1, map->file2, | 300 if (patience_diff(map->file1, map->file2, |
341 { | 341 { |
342 struct hashmap map; | 342 struct hashmap map; |
343 struct entry *first; | 343 struct entry *first; |
344 int result = 0; | 344 int result = 0; |
345 | 345 |
346 /* trivial case: one side is empty */ | 346 // trivial case: one side is empty |
347 if (!count1) { | 347 if (!count1) { |
348 while(count2--) | 348 while(count2--) |
349 env->xdf2.rchg[line2++ - 1] = 1; | 349 env->xdf2.rchg[line2++ - 1] = 1; |
350 return 0; | 350 return 0; |
351 } else if (!count2) { | 351 } else if (!count2) { |
357 memset(&map, 0, sizeof(map)); | 357 memset(&map, 0, sizeof(map)); |
358 if (fill_hashmap(file1, file2, xpp, env, &map, | 358 if (fill_hashmap(file1, file2, xpp, env, &map, |
359 line1, count1, line2, count2)) | 359 line1, count1, line2, count2)) |
360 return -1; | 360 return -1; |
361 | 361 |
362 /* are there any matching lines at all? */ | 362 // are there any matching lines at all? |
363 if (!map.has_matches) { | 363 if (!map.has_matches) { |
364 while(count1--) | 364 while(count1--) |
365 env->xdf1.rchg[line1++ - 1] = 1; | 365 env->xdf1.rchg[line1++ - 1] = 1; |
366 while(count2--) | 366 while(count2--) |
367 env->xdf2.rchg[line2++ - 1] = 1; | 367 env->xdf2.rchg[line2++ - 1] = 1; |
385 xpparam_t const *xpp, xdfenv_t *env) | 385 xpparam_t const *xpp, xdfenv_t *env) |
386 { | 386 { |
387 if (xdl_prepare_env(file1, file2, xpp, env) < 0) | 387 if (xdl_prepare_env(file1, file2, xpp, env) < 0) |
388 return -1; | 388 return -1; |
389 | 389 |
390 /* environment is cleaned up in xdl_diff() */ | 390 // environment is cleaned up in xdl_diff() |
391 return patience_diff(file1, file2, xpp, env, | 391 return patience_diff(file1, file2, xpp, env, |
392 1, env->xdf1.nrec, 1, env->xdf2.nrec); | 392 1, env->xdf1.nrec, 1, env->xdf2.nrec); |
393 } | 393 } |