提交 490d6ab1 编写于 作者: Z Zach Brown 提交者: Linus Torvalds

[PATCH] 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: NZach Brown <zach.brown@oracle.com>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 bcc68b86
...@@ -34,9 +34,11 @@ struct list_head { ...@@ -34,9 +34,11 @@ struct list_head {
#define LIST_HEAD(name) \ #define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name) struct list_head name = LIST_HEAD_INIT(name)
#define INIT_LIST_HEAD(ptr) do { \ static inline void INIT_LIST_HEAD(struct list_head *list)
(ptr)->next = (ptr); (ptr)->prev = (ptr); \ {
} while (0) list->next = list;
list->prev = list;
}
/* /*
* Insert a new entry between two known consecutive entries. * Insert a new entry between two known consecutive entries.
...@@ -534,7 +536,11 @@ struct hlist_node { ...@@ -534,7 +536,11 @@ struct hlist_node {
#define HLIST_HEAD_INIT { .first = NULL } #define HLIST_HEAD_INIT { .first = NULL }
#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL } #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
#define INIT_HLIST_HEAD(ptr) ((ptr)->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) static inline int hlist_unhashed(const struct hlist_node *h)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册