diff options
author | Pierre Habouzit <madcoder@debian.org> | 2009-07-23 01:34:34 +0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-07-23 08:57:41 +0400 |
commit | f630cfda8800aee03c7eb2fcd0f840730fbe43b9 (patch) | |
tree | f780eac20525e629c704a31a8d6e629cae6ea011 | |
parent | 67da52bedc5750c10a732b9da7d64d5ef73f3b8a (diff) |
refactor: use bitsizeof() instead of 8 * sizeof()
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | git-compat-util.h | 3 | ||||
-rw-r--r-- | sha1_file.c | 2 | ||||
-rw-r--r-- | xdiff/xdiffi.c | 2 |
3 files changed, 4 insertions, 3 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index 913f41a42c..6dfc0ddd90 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -26,6 +26,7 @@ #endif #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) +#define bitsizeof(x) (CHAR_BIT * sizeof(x)) #ifdef __GNUC__ #define TYPEOF(x) (__typeof__(x)) @@ -33,7 +34,7 @@ #define TYPEOF(x) #endif -#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (sizeof(x) * 8 - (bits)))) +#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits)))) #define HAS_MULTI_BITS(i) ((i) & ((i) - 1)) /* checks if an integer has more than 1 bit set */ /* Approximation of the length of the decimal representation of this type. */ diff --git a/sha1_file.c b/sha1_file.c index 4576ff77f3..1d996a1990 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1170,7 +1170,7 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf, size = c & 15; shift = 4; while (c & 0x80) { - if (len <= used || sizeof(long) * 8 <= shift) { + if (len <= used || bitsizeof(long) <= shift) { error("bad object header"); return 0; } diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c index 1ebab687f7..da67c04357 100644 --- a/xdiff/xdiffi.c +++ b/xdiff/xdiffi.c @@ -26,7 +26,7 @@ #define XDL_MAX_COST_MIN 256 #define XDL_HEUR_MIN_COST 256 -#define XDL_LINE_MAX (long)((1UL << (8 * sizeof(long) - 1)) - 1) +#define XDL_LINE_MAX (long)((1UL << (CHAR_BIT * sizeof(long) - 1)) - 1) #define XDL_SNAKE_CNT 20 #define XDL_K_HEUR 4 |