unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/3] lib: abstract bit validity check in bit test/set/clear macros
@ 2015-02-23 16:56 Jani Nikula
  2015-02-23 16:56 ` [PATCH 2/3] lib: fix clang build warnings Jani Nikula
  2015-02-23 16:56 ` [PATCH 3/3] cli: " Jani Nikula
  0 siblings, 2 replies; 5+ messages in thread
From: Jani Nikula @ 2015-02-23 16:56 UTC (permalink / raw)
  To: notmuch

Reduce duplication in the bit test/set/clear macros. No functional
changes.
---
 lib/notmuch-private.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index 012ad25c42cd..02a8fc62b631 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -64,15 +64,14 @@ NOTMUCH_BEGIN_DECLS
     strncmp ((var), (literal), sizeof (literal) - 1)
 
 /* Robust bit test/set/reset macros */
+#define _NOTMUCH_VALID_BIT(bit) \
+    ((bit) >= 0 && (bit) < CHAR_BIT * sizeof (unsigned long long))
 #define NOTMUCH_TEST_BIT(val, bit) \
-    (((bit) < 0 || (bit) >= CHAR_BIT * sizeof (unsigned long long)) ? 0	\
-     : !!((val) & (1ull << (bit))))
+    (_NOTMUCH_VALID_BIT(bit) ? !!((val) & (1ull << (bit))) : 0)
 #define NOTMUCH_SET_BIT(valp, bit) \
-    (((bit) < 0 || (bit) >= CHAR_BIT * sizeof (unsigned long long)) ? *(valp) \
-     : (*(valp) |= (1ull << (bit))))
+    (_NOTMUCH_VALID_BIT(bit) ? (*(valp) |= (1ull << (bit))) : *(valp))
 #define NOTMUCH_CLEAR_BIT(valp,  bit) \
-    (((bit) < 0 || (bit) >= CHAR_BIT * sizeof (unsigned long long)) ? *(valp) \
-     : (*(valp) &= ~(1ull << (bit))))
+    (_NOTMUCH_VALID_BIT(bit) ? (*(valp) &= ~(1ull << (bit))) : *(valp))
 
 #define unused(x) x __attribute__ ((unused))
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-02-25 22:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-23 16:56 [PATCH 1/3] lib: abstract bit validity check in bit test/set/clear macros Jani Nikula
2015-02-23 16:56 ` [PATCH 2/3] lib: fix clang build warnings Jani Nikula
2015-02-23 16:56 ` [PATCH 3/3] cli: " Jani Nikula
2015-02-23 19:11   ` Tomi Ollila
2015-02-25 22:14     ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).