mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zach Brown <zach.brown@oracle.com>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@osdl.org>
Subject: [PATCH] [list.h] don't evaluate macro args multiple times
Date: Thu, 12 Jan 2006 16:43:56 -0800 (PST)	[thread overview]
Message-ID: <20060113004356.11419.50021.sendpatchset@tetsuo.zabbo.net> (raw)


[list.h] don't evaluate macro args multiple times

I noticed that list.h init functions were evaluating macro arguments multiple
times and thought it might be nice to protect the unsuspecting caller.
Converting the macros to inline functions seems to reduce code size, too.  A
i386 defconfig build with gcc 3.3.3 from fc4:

   text    data     bss     dec     hex filename
3573148  565664  188828 4327640  4208d8 vmlinux.before
3572177  565664  188828 4326669  42050d vmlinux

add/remove: 0/0 grow/shrink: 11/144 up/down: 88/-1016 (-928)

There was no difference in checkstack output.

  Signed-off-by: Zach Brown <zach.brown@oracle.com>
---

 include/linux/list.h |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

Index: 2.6.15-git8-misc/include/linux/list.h
===================================================================
--- 2.6.15-git8-misc.orig/include/linux/list.h	2006-01-12 15:27:37.442709075 -0800
+++ 2.6.15-git8-misc/include/linux/list.h	2006-01-12 15:46:03.907589898 -0800
@@ -34,9 +34,11 @@
 #define LIST_HEAD(name) \
 	struct list_head name = LIST_HEAD_INIT(name)
 
-#define INIT_LIST_HEAD(ptr) do { \
-	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
-} while (0)
+static inline void INIT_LIST_HEAD(struct list_head *list)
+{
+	list->next = list;
+	list->prev = list;
+}
 
 /*
  * Insert a new entry between two known consecutive entries.
@@ -534,7 +536,11 @@
 #define HLIST_HEAD_INIT { .first = NULL }
 #define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
-#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
+static inline void INIT_HLIST_NODE(struct hlist_node *h)
+{
+	h->next = NULL;
+	h->pprev = NULL;
+}
 
 static inline int hlist_unhashed(const struct hlist_node *h)
 {

                 reply	other threads:[~2006-01-13  0:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20060113004356.11419.50021.sendpatchset@tetsuo.zabbo.net \
    --to=zach.brown@oracle.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®