Skip to content

Commit 14d3d90

Browse files
authored
Merge pull request #242 from compnerd/sizeof
Use sizeof more pervasively
2 parents 2df80a3 + 7f2576c commit 14d3d90

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

src/allocator.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,7 @@ _dispatch_alloc_init(void)
601601
// Double-check our math. These are all compile time checks and don't
602602
// generate code.
603603

604-
dispatch_assert(sizeof(bitmap_t) == BYTES_PER_BITMAP);
605604
dispatch_assert(sizeof(bitmap_t) == BYTES_PER_SUPERMAP);
606-
dispatch_assert(sizeof(struct dispatch_magazine_header_s) ==
607-
SIZEOF_HEADER);
608605

609606
dispatch_assert(sizeof(struct dispatch_continuation_s) <=
610607
DISPATCH_CONTINUATION_SIZE);
@@ -614,8 +611,6 @@ _dispatch_alloc_init(void)
614611
dispatch_assert(sizeof(struct dispatch_magazine_s) == BYTES_PER_MAGAZINE);
615612

616613
// The header and maps sizes should match what we computed.
617-
dispatch_assert(SIZEOF_HEADER ==
618-
sizeof(((struct dispatch_magazine_s *)0x0)->header));
619614
dispatch_assert(SIZEOF_MAPS ==
620615
sizeof(((struct dispatch_magazine_s *)0x0)->maps));
621616

src/allocator_internal.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,21 @@
9797
// Use the largest type your platform is comfortable doing atomic ops with.
9898
// TODO: rdar://11477843
9999
typedef unsigned long bitmap_t;
100-
#if defined(__LP64__)
101-
#define BYTES_PER_BITMAP 8
102-
#else
103-
#define BYTES_PER_BITMAP 4
104-
#endif
100+
#define BYTES_PER_BITMAP sizeof(bitmap_t)
105101

106102
#define BITMAP_C(v) ((bitmap_t)(v))
107103
#define BITMAP_ALL_ONES (~BITMAP_C(0))
108104

109105
// Stop configuring.
110106

111-
#define CONTINUATIONS_PER_BITMAP (BYTES_PER_BITMAP * 8)
112-
#define BITMAPS_PER_SUPERMAP (BYTES_PER_SUPERMAP * 8)
107+
#define CONTINUATIONS_PER_BITMAP (BYTES_PER_BITMAP * CHAR_BIT)
108+
#define BITMAPS_PER_SUPERMAP (BYTES_PER_SUPERMAP * CHAR_BIT)
113109

114110
#define BYTES_PER_MAGAZINE (PAGES_PER_MAGAZINE * DISPATCH_ALLOCATOR_PAGE_SIZE)
115111
#define CONSUMED_BYTES_PER_BITMAP (BYTES_PER_BITMAP + \
116112
(DISPATCH_CONTINUATION_SIZE * CONTINUATIONS_PER_BITMAP))
117113

118-
#define BYTES_PER_SUPERMAP BYTES_PER_BITMAP
114+
#define BYTES_PER_SUPERMAP sizeof(bitmap_t)
119115
#define CONSUMED_BYTES_PER_SUPERMAP (BYTES_PER_SUPERMAP + \
120116
(BITMAPS_PER_SUPERMAP * CONSUMED_BYTES_PER_BITMAP))
121117

@@ -147,11 +143,7 @@ typedef unsigned long bitmap_t;
147143

148144
#define PADDING_TO_CONTINUATION_SIZE(x) (ROUND_UP_TO_CONTINUATION_SIZE(x) - (x))
149145

150-
#if defined(__LP64__)
151-
#define SIZEOF_HEADER 16
152-
#else
153-
#define SIZEOF_HEADER 8
154-
#endif
146+
#define SIZEOF_HEADER (sizeof(struct dispatch_magazine_header_s))
155147

156148
#define SIZEOF_SUPERMAPS (BYTES_PER_SUPERMAP * SUPERMAPS_PER_MAGAZINE)
157149
#define SIZEOF_MAPS (BYTES_PER_BITMAP * BITMAPS_PER_SUPERMAP * \

0 commit comments

Comments
 (0)