Skip to content

Commit b8688ad

Browse files
committed
Merge branch 'rs/qsort'
We call "qsort(array, nelem, sizeof(array[0]), fn)", and most of the time third parameter is redundant. A new QSORT() macro lets us omit it. * rs/qsort: show-branch: use QSORT use QSORT, part 2 coccicheck: use --all-includes by default remove unnecessary check before QSORT use QSORT add QSORT
2 parents a23ca1b + 7e65c75 commit b8688ad

35 files changed

+97
-78
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ SPATCH = spatch
467467
export TCL_PATH TCLTK_PATH
468468

469469
SPARSE_FLAGS =
470+
SPATCH_FLAGS = --all-includes
470471

471472

472473

@@ -2314,7 +2315,7 @@ C_SOURCES = $(patsubst %.o,%.c,$(C_OBJ))
23142315
%.cocci.patch: %.cocci $(C_SOURCES)
23152316
@echo ' ' SPATCH $<; \
23162317
for f in $(C_SOURCES); do \
2317-
$(SPATCH) --sp-file $< $$f; \
2318+
$(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS); \
23182319
done >$@ 2>$@.log; \
23192320
if test -s $@; \
23202321
then \

bisect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
215215
array[cnt].distance = distance;
216216
cnt++;
217217
}
218-
qsort(array, cnt, sizeof(*array), compare_commit_dist);
218+
QSORT(array, cnt, compare_commit_dist);
219219
for (p = list, i = 0; i < cnt; i++) {
220220
char buf[100]; /* enough for dist=%d */
221221
struct object *obj = &(array[i].commit->object);

builtin/describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static void describe(const char *arg, int last_one)
352352
oid_to_hex(oid));
353353
}
354354

355-
qsort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt);
355+
QSORT(all_matches, match_cnt, compare_pt);
356356

357357
if (gave_up_on) {
358358
commit_list_insert_by_date(gave_up_on, &list);

builtin/fast-export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static void show_filemodify(struct diff_queue_struct *q,
347347
* Handle files below a directory first, in case they are all deleted
348348
* and the directory changes to a file or symlink.
349349
*/
350-
qsort(q->queue, q->nr, sizeof(q->queue[0]), depth_first);
350+
QSORT(q->queue, q->nr, depth_first);
351351

352352
for (i = 0; i < q->nr; i++) {
353353
struct diff_filespec *ospec = q->queue[i]->one;

builtin/fmt-merge-msg.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,10 @@ static void add_people_info(struct strbuf *out,
314314
struct string_list *authors,
315315
struct string_list *committers)
316316
{
317-
if (authors->nr)
318-
qsort(authors->items,
319-
authors->nr, sizeof(authors->items[0]),
320-
cmp_string_list_util_as_integral);
321-
if (committers->nr)
322-
qsort(committers->items,
323-
committers->nr, sizeof(committers->items[0]),
324-
cmp_string_list_util_as_integral);
317+
QSORT(authors->items, authors->nr,
318+
cmp_string_list_util_as_integral);
319+
QSORT(committers->items, committers->nr,
320+
cmp_string_list_util_as_integral);
325321

326322
credit_people(out, authors, 'a');
327323
credit_people(out, committers, 'c');

builtin/index-pack.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,10 +1190,8 @@ static void resolve_deltas(void)
11901190
return;
11911191

11921192
/* Sort deltas by base SHA1/offset for fast searching */
1193-
qsort(ofs_deltas, nr_ofs_deltas, sizeof(struct ofs_delta_entry),
1194-
compare_ofs_delta_entry);
1195-
qsort(ref_deltas, nr_ref_deltas, sizeof(struct ref_delta_entry),
1196-
compare_ref_delta_entry);
1193+
QSORT(ofs_deltas, nr_ofs_deltas, compare_ofs_delta_entry);
1194+
QSORT(ref_deltas, nr_ref_deltas, compare_ref_delta_entry);
11971195

11981196
if (verbose || show_resolving_progress)
11991197
progress = start_progress(_("Resolving deltas"),
@@ -1356,7 +1354,7 @@ static void fix_unresolved_deltas(struct sha1file *f)
13561354
ALLOC_ARRAY(sorted_by_pos, nr_ref_deltas);
13571355
for (i = 0; i < nr_ref_deltas; i++)
13581356
sorted_by_pos[i] = &ref_deltas[i];
1359-
qsort(sorted_by_pos, nr_ref_deltas, sizeof(*sorted_by_pos), delta_pos_compare);
1357+
QSORT(sorted_by_pos, nr_ref_deltas, delta_pos_compare);
13601358

13611359
for (i = 0; i < nr_ref_deltas; i++) {
13621360
struct ref_delta_entry *d = sorted_by_pos[i];
@@ -1533,8 +1531,7 @@ static void read_v2_anomalous_offsets(struct packed_git *p,
15331531
opts->anomaly[opts->anomaly_nr++] = ntohl(idx2[off * 2 + 1]);
15341532
}
15351533

1536-
if (1 < opts->anomaly_nr)
1537-
qsort(opts->anomaly, opts->anomaly_nr, sizeof(uint32_t), cmp_uint32);
1534+
QSORT(opts->anomaly, opts->anomaly_nr, cmp_uint32);
15381535
}
15391536

15401537
static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)

builtin/mktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static void write_tree(unsigned char *sha1)
4646
size_t size;
4747
int i;
4848

49-
qsort(entries, used, sizeof(*entries), ent_compare);
49+
QSORT(entries, used, ent_compare);
5050
for (size = i = 0; i < used; i++)
5151
size += 32 + entries[i]->len;
5252

builtin/name-rev.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ static const char *get_exact_ref_match(const struct object *o)
195195
return NULL;
196196

197197
if (!tip_table.sorted) {
198-
qsort(tip_table.table, tip_table.nr, sizeof(*tip_table.table),
199-
tipcmp);
198+
QSORT(tip_table.table, tip_table.nr, tipcmp);
200199
tip_table.sorted = 1;
201200
}
202201

builtin/pack-objects.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ static void get_object_details(void)
15351535
sorted_by_offset = xcalloc(to_pack.nr_objects, sizeof(struct object_entry *));
15361536
for (i = 0; i < to_pack.nr_objects; i++)
15371537
sorted_by_offset[i] = to_pack.objects + i;
1538-
qsort(sorted_by_offset, to_pack.nr_objects, sizeof(*sorted_by_offset), pack_offset_sort);
1538+
QSORT(sorted_by_offset, to_pack.nr_objects, pack_offset_sort);
15391539

15401540
for (i = 0; i < to_pack.nr_objects; i++) {
15411541
struct object_entry *entry = sorted_by_offset[i];
@@ -2257,7 +2257,7 @@ static void prepare_pack(int window, int depth)
22572257
if (progress)
22582258
progress_state = start_progress(_("Compressing objects"),
22592259
nr_deltas);
2260-
qsort(delta_list, n, sizeof(*delta_list), type_size_sort);
2260+
QSORT(delta_list, n, type_size_sort);
22612261
ll_find_deltas(delta_list, n, window+1, depth, &nr_done);
22622262
stop_progress(&progress_state);
22632263
if (nr_done != nr_deltas)
@@ -2449,8 +2449,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
24492449
}
24502450

24512451
if (in_pack.nr) {
2452-
qsort(in_pack.array, in_pack.nr, sizeof(in_pack.array[0]),
2453-
ofscmp);
2452+
QSORT(in_pack.array, in_pack.nr, ofscmp);
24542453
for (i = 0; i < in_pack.nr; i++) {
24552454
struct object *o = in_pack.array[i].object;
24562455
add_object_entry(o->oid.hash, o->type, "", 0);

builtin/remote.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,8 +1197,7 @@ static int show(int argc, const char **argv)
11971197

11981198
info.width = info.width2 = 0;
11991199
for_each_string_list(&states.push, add_push_to_show_info, &info);
1200-
qsort(info.list->items, info.list->nr,
1201-
sizeof(*info.list->items), cmp_string_with_push);
1200+
QSORT(info.list->items, info.list->nr, cmp_string_with_push);
12021201
if (info.list->nr)
12031202
printf_ln(Q_(" Local ref configured for 'git push'%s:",
12041203
" Local refs configured for 'git push'%s:",

0 commit comments

Comments
 (0)