From: Pierre Habouzit <madcoder@debian.org>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Pierre Habouzit <madcoder@debian.org>
Subject: [PATCH 2/3] refactor: use bitsizeof() instead of 8 * sizeof()
Date: Wed, 22 Jul 2009 23:34:34 +0200 [thread overview]
Message-ID: <1248298475-2990-3-git-send-email-madcoder@debian.org> (raw)
In-Reply-To: <1248298475-2990-2-git-send-email-madcoder@debian.org>
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
git-compat-util.h | 3 ++-
sha1_file.c | 2 +-
xdiff/xdiffi.c | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 913f41a..6dfc0dd 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 b91a7dd..4ea0b18 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 1ebab68..da67c04 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
--
1.6.4.rc1.192.g631f9
next prev parent reply other threads:[~2009-07-22 21:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-22 21:34 janitoring Pierre Habouzit
2009-07-22 21:34 ` [PATCH 1/3] janitor: use NULL and not 0 for pointers Pierre Habouzit
2009-07-22 21:34 ` Pierre Habouzit [this message]
2009-07-22 21:34 ` [PATCH 3/3] janitor: add DIV_ROUND_UP and use it Pierre Habouzit
2009-07-23 5:07 ` [PATCH 2/3] refactor: use bitsizeof() instead of 8 * sizeof() Jeff King
2009-07-23 5:09 ` Junio C Hamano
2009-07-23 5:11 ` Jeff King
2009-07-23 5:15 ` Junio C Hamano
2009-07-23 6:22 ` Pierre Habouzit
2009-07-22 22:00 ` janitoring Junio C Hamano
2009-07-22 22:02 ` janitoring Pierre Habouzit
2009-07-22 22:19 ` janitoring Junio C Hamano
2009-07-22 22:29 ` janitoring Johannes Schindelin
2009-07-23 7:27 ` janitoring Johannes Sixt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1248298475-2990-3-git-send-email-madcoder@debian.org \
--to=madcoder@debian.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.