refactor: use bitsizeof() instead of 8 * sizeof()
Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pierre Habouzit committed
Jul 22, 2009 at 23:34 UTC
f630cfda8800aee03c7eb2fcd0f840730fbe43b9
3 files changed
+4
-3
git-compat-util.h
+2
-1
@@ -26,6 +26,7 @@
26
#endif
27
28
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
29
+#define bitsizeof(x) (CHAR_BIT * sizeof(x))
30
31
#ifdef __GNUC__
32
#define TYPEOF(x) (__typeof__(x))
@@ -33,7 +34,7 @@
34
#define TYPEOF(x)
35
#endif
36
36
-#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (sizeof(x) * 8 - (bits))))
37
+#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))
38
#define HAS_MULTI_BITS(i) ((i) & ((i) - 1)) /* checks if an integer has more than 1 bit set */
39
40
/* Approximation of the length of the decimal representation of this type. */
sha1_file.c
+1
-1
@@ -1170,7 +1170,7 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
1170
size = c & 15;
1171
shift = 4;
1172
while (c & 0x80) {
1173
- if (len <= used || sizeof(long) * 8 <= shift) {
1173
+ if (len <= used || bitsizeof(long) <= shift) {
1174
error("bad object header");
1175
return 0;
1176
}
xdiff/xdiffi.c
+1
-1
@@ -26,7 +26,7 @@
26
27
#define XDL_MAX_COST_MIN 256
28
#define XDL_HEUR_MIN_COST 256
29
-#define XDL_LINE_MAX (long)((1UL << (8 * sizeof(long) - 1)) - 1)
29
+#define XDL_LINE_MAX (long)((1UL << (CHAR_BIT * sizeof(long) - 1)) - 1)
30
#define XDL_SNAKE_CNT 20
31
#define XDL_K_HEUR 4
32