Skip to content

Commit f056cde

Browse files
committed
Merge branch 'rs/use-div-round-up'
Code cleanup. * rs/use-div-round-up: use DIV_ROUND_UP
2 parents 768d0fe + 42c78a2 commit f056cde

File tree

9 files changed

+14
-15
lines changed

9 files changed

+14
-15
lines changed

builtin/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static int too_many_loose_objects(void)
149149
if (!dir)
150150
return 0;
151151

152-
auto_threshold = (gc_auto_threshold + 255) / 256;
152+
auto_threshold = DIV_ROUND_UP(gc_auto_threshold, 256);
153153
while ((ent = readdir(dir)) != NULL) {
154154
if (strspn(ent->d_name, "0123456789abcdef") != 38 ||
155155
ent->d_name[38] != '\0')

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ static void compile_submodule_options(const struct grep_opt *opt,
543543
* submodule process has its own thread pool.
544544
*/
545545
argv_array_pushf(&submodule_options, "--threads=%d",
546-
(num_threads + 1) / 2);
546+
DIV_ROUND_UP(num_threads, 2));
547547

548548
/* Add Pathspecs */
549549
argv_array_push(&submodule_options, "--");

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ static struct commit *get_base_commit(const char *base_commit,
13081308

13091309
if (rev_nr % 2)
13101310
rev[i] = rev[2 * i];
1311-
rev_nr = (rev_nr + 1) / 2;
1311+
rev_nr = DIV_ROUND_UP(rev_nr, 2);
13121312
}
13131313

13141314
if (!in_merge_bases(base, rev[0]))

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ static const char *unpack_with_sideband(struct shallow_info *si)
18061806
static void prepare_shallow_update(struct command *commands,
18071807
struct shallow_info *si)
18081808
{
1809-
int i, j, k, bitmap_size = (si->ref->nr + 31) / 32;
1809+
int i, j, k, bitmap_size = DIV_ROUND_UP(si->ref->nr, 32);
18101810

18111811
ALLOC_ARRAY(si->used_shallow, si->shallow->nr);
18121812
assign_shallow_commits_to_refs(si, si->used_shallow, NULL);

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *o
20952095
* bytes per "line".
20962096
* This is stupid and ugly, but very cheap...
20972097
*/
2098-
damage = (damage + 63) / 64;
2098+
damage = DIV_ROUND_UP(damage, 64);
20992099
ALLOC_GROW(dir.files, dir.nr + 1, dir.alloc);
21002100
dir.files[dir.nr].name = file->name;
21012101
dir.files[dir.nr].changed = damage;

ewah/ewah_bitmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ size_t ewah_add(struct ewah_bitmap *self, eword_t word)
210210
void ewah_set(struct ewah_bitmap *self, size_t i)
211211
{
212212
const size_t dist =
213-
(i + BITS_IN_EWORD) / BITS_IN_EWORD -
214-
(self->bit_size + BITS_IN_EWORD - 1) / BITS_IN_EWORD;
213+
DIV_ROUND_UP(i + 1, BITS_IN_EWORD) -
214+
DIV_ROUND_UP(self->bit_size, BITS_IN_EWORD);
215215

216216
assert(i >= self->bit_size);
217217

imap-send.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ static char hexchar(unsigned int b)
861861
return b < 10 ? '0' + b : 'a' + (b - 10);
862862
}
863863

864-
#define ENCODED_SIZE(n) (4*((n+2)/3))
864+
#define ENCODED_SIZE(n) (4 * DIV_ROUND_UP((n), 3))
865865
static char *cram(const char *challenge_64, const char *user, const char *pass)
866866
{
867867
int i, resp_len, encoded_len, decoded_len;

sha1_name.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,9 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
489489
* We now know we have on the order of 2^len objects, which
490490
* expects a collision at 2^(len/2). But we also care about hex
491491
* chars, not bits, and there are 4 bits per hex. So all
492-
* together we need to divide by 2; but we also want to round
493-
* odd numbers up, hence adding one before dividing.
492+
* together we need to divide by 2 and round up.
494493
*/
495-
len = (len + 1) / 2;
494+
len = DIV_ROUND_UP(len, 2);
496495
/*
497496
* For very small repos, we stick with our regular fallback.
498497
*/

shallow.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ struct paint_info {
443443

444444
static uint32_t *paint_alloc(struct paint_info *info)
445445
{
446-
unsigned nr = (info->nr_bits + 31) / 32;
446+
unsigned nr = DIV_ROUND_UP(info->nr_bits, 32);
447447
unsigned size = nr * sizeof(uint32_t);
448448
void *p;
449449
if (!info->pool_count || size > info->end - info->free) {
@@ -471,7 +471,7 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
471471
{
472472
unsigned int i, nr;
473473
struct commit_list *head = NULL;
474-
int bitmap_nr = (info->nr_bits + 31) / 32;
474+
int bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32);
475475
size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);
476476
struct commit *c = lookup_commit_reference_gently(oid, 1);
477477
uint32_t *tmp; /* to be freed before return */
@@ -611,7 +611,7 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
611611
paint_down(&pi, ref->oid + i, i);
612612

613613
if (used) {
614-
int bitmap_size = ((pi.nr_bits + 31) / 32) * sizeof(uint32_t);
614+
int bitmap_size = DIV_ROUND_UP(pi.nr_bits, 32) * sizeof(uint32_t);
615615
memset(used, 0, sizeof(*used) * info->shallow->nr);
616616
for (i = 0; i < nr_shallow; i++) {
617617
const struct commit *c = lookup_commit(&oid[shallow[i]]);
@@ -672,7 +672,7 @@ static void post_assign_shallow(struct shallow_info *info,
672672
struct commit *c;
673673
uint32_t **bitmap;
674674
int dst, i, j;
675-
int bitmap_nr = (info->ref->nr + 31) / 32;
675+
int bitmap_nr = DIV_ROUND_UP(info->ref->nr, 32);
676676
struct commit_array ca;
677677

678678
trace_printf_key(&trace_shallow, "shallow: post_assign_shallow\n");

0 commit comments

Comments
 (0)