| 250 | } |
| 251 | |
| 252 | static void find_exact_matches(struct string_list *a, struct string_list *b) |
| 253 | { |
| 254 | struct hashmap map = HASHMAP_INIT(patch_util_cmp, NULL); |
| 255 | int i; |
| 256 | |
| 257 | /* First, add the patches of a to a hash map */ |
| 258 | for (i = 0; i < a->nr; i++) { |
| 259 | struct patch_util *util = a->items[i].util; |
| 260 | |
| 261 | util->i = i; |
| 262 | util->patch = a->items[i].string; |
| 263 | util->diff = util->patch + util->diff_offset; |
| 264 | hashmap_entry_init(&util->e, strhash(util->diff)); |
| 265 | hashmap_add(&map, &util->e); |
| 266 | } |
| 267 | |
| 268 | /* Now try to find exact matches in b */ |
| 269 | for (i = 0; i < b->nr; i++) { |
| 270 | struct patch_util *util = b->items[i].util, *other; |
| 271 | |
| 272 | util->i = i; |
| 273 | util->patch = b->items[i].string; |
| 274 | util->diff = util->patch + util->diff_offset; |
| 275 | hashmap_entry_init(&util->e, strhash(util->diff)); |
| 276 | other = hashmap_remove_entry(&map, util, e, NULL); |
| 277 | if (other) { |
| 278 | if (other->matching >= 0) |
| 279 | BUG("already assigned!"); |
| 280 | |
| 281 | other->matching = i; |
| 282 | util->matching = other->i; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | hashmap_clear(&map); |
| 287 | } |
| 288 | |
| 289 | static int diffsize_consume(void *data, |
| 290 | char *line UNUSED, |
no test coverage detected