MCPcopy Create free account
hub / github.com/git/git / compute_xor_offsets

Function compute_xor_offsets

pack-bitmap-write.c:345–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

343}
344
345static void compute_xor_offsets(struct bitmap_writer *writer)
346{
347 static const int MAX_XOR_OFFSET_SEARCH = 10;
348
349 int i, next = 0;
350 int nr = bitmap_writer_nr_selected_commits(writer);
351
352 if (nr > 1) {
353 QSORT(writer->selected, nr, bitmapped_commit_date_cmp);
354
355 for (i = 0; i < nr; i++) {
356 struct bitmapped_commit *stored = &writer->selected[i];
357 khiter_t hash_pos = kh_get_oid_map(writer->bitmaps,
358 stored->commit->object.oid);
359
360 if (hash_pos == kh_end(writer->bitmaps))
361 BUG("selected commit missing from bitmap map: %s",
362 oid_to_hex(&stored->commit->object.oid));
363
364 kh_value(writer->bitmaps, hash_pos) = stored;
365 }
366 }
367
368 while (next < writer->selected_nr) {
369 struct bitmapped_commit *stored = &writer->selected[next];
370 int best_offset = 0;
371 struct ewah_bitmap *best_bitmap = stored->bitmap;
372 struct ewah_bitmap *test_xor;
373
374 if (stored->pseudo_merge)
375 goto next;
376
377 for (i = 1; i <= MAX_XOR_OFFSET_SEARCH; ++i) {
378 int curr = next - i;
379
380 if (curr < 0)
381 break;
382 if (writer->selected[curr].pseudo_merge)
383 continue;
384
385 test_xor = ewah_pool_new();
386 ewah_xor(writer->selected[curr].bitmap, stored->bitmap, test_xor);
387
388 if (test_xor->buffer_size < best_bitmap->buffer_size) {
389 if (best_bitmap != stored->bitmap)
390 ewah_pool_free(best_bitmap);
391
392 best_bitmap = test_xor;
393 best_offset = i;
394 } else {
395 ewah_pool_free(test_xor);
396 }
397 }
398
399next:
400 stored->xor_offset = best_offset;
401 stored->write_as = best_bitmap;
402

Callers 1

bitmap_writer_buildFunction · 0.85

Calls 5

oid_to_hexFunction · 0.85
ewah_pool_newFunction · 0.85
ewah_xorFunction · 0.85
ewah_pool_freeFunction · 0.85

Tested by

no test coverage detected