[PATCH 1/9] ptrlist: specialize __add_ptr_list() for tag/notag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently, the function to add items to ptrlists, __add_ptr_list(),
always combine a 'raw' pointer and a tag.

But the vast majority of list entries have no tag and so just need
to store the raw pointer.

Avoid to do this operation when it's not needed by specializing
this function like this:
- __add_ptr_list() which directly store an untagged or 'cooked' ptr.
- __add_ptr_list_tag() which combine a pointer and a tag and then
  store this 'cooked' pointer by calling __add_ptr_list().

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 ptrlist.c | 33 +++++++++++++++++++++++----------
 ptrlist.h | 16 ++++++++--------
 2 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/ptrlist.c b/ptrlist.c
index 7f6bfbe32..c1366f0d0 100644
--- a/ptrlist.c
+++ b/ptrlist.c
@@ -141,24 +141,17 @@ void split_ptr_list_head(struct ptr_list *head)
 // add an entry to a ptrlist
 // @listp: a pointer to the list
 // @ptr: the entry to add to the list
-// @tag: the tag to add to **ptr**, usually ``0``.
 // @return: the address where the new entry is stored.
 //
-// :note: code must not use this function and should use one of
-//	:func:`add_ptr_list`, :func:`add_ptr_list_notag` or
-//	:func:`add_ptr_list_tag` instead.
-void **__add_ptr_list(struct ptr_list **listp, void *ptr, unsigned long tag)
+// :note: code must not use this function and should use
+//	:func:`add_ptr_list` instead.
+void **__add_ptr_list(struct ptr_list **listp, void *ptr)
 {
 	struct ptr_list *list = *listp;
 	struct ptr_list *last = NULL; /* gcc complains needlessly */
 	void **ret;
 	int nr;
 
-	/* The low two bits are reserved for tags */
-	assert((3 & (unsigned long)ptr) == 0);
-	assert((~3 & tag) == 0);
-	ptr = (void *)(tag | (unsigned long)ptr);
-
 	if (!list || (nr = (last = list->prev)->nr) >= LIST_NODE_NR) {
 		struct ptr_list *newlist = __alloc_ptrlist(0);
 		if (!list) {
@@ -181,6 +174,26 @@ void **__add_ptr_list(struct ptr_list **listp, void *ptr, unsigned long tag)
 	return ret;
 }
 
+///
+// add a tagged entry to a ptrlist
+// @listp: a pointer to the list
+// @ptr: the entry to add to the list
+// @tag: the tag to add to @ptr
+// @return: the address where the new entry is stored.
+//
+// :note: code must not use this function and should use
+//	:func:`add_ptr_list_tag` instead.
+void **__add_ptr_list_tag(struct ptr_list **listp, void *ptr, unsigned long tag)
+{
+	/* The low two bits are reserved for tags */
+	assert((3 & (unsigned long)ptr) == 0);
+	assert((~3 & tag) == 0);
+
+	ptr = (void *)(tag | (unsigned long)ptr);
+
+	return __add_ptr_list(listp, ptr);
+}
+
 ///
 // delete an entry from a ptrlist
 // @list: a pointer to the list
diff --git a/ptrlist.h b/ptrlist.h
index 4451ee33f..f3902a736 100644
--- a/ptrlist.h
+++ b/ptrlist.h
@@ -40,7 +40,8 @@ int delete_ptr_list_entry(struct ptr_list **, void *, int);
 int replace_ptr_list_entry(struct ptr_list **, void *old, void *new, int);
 extern void sort_list(struct ptr_list **, int (*)(const void *, const void *));
 
-extern void **__add_ptr_list(struct ptr_list **, void *, unsigned long);
+extern void **__add_ptr_list(struct ptr_list **, void *);
+extern void **__add_ptr_list_tag(struct ptr_list **, void *, unsigned long);
 extern void concat_ptr_list(struct ptr_list *a, struct ptr_list **b);
 extern void __free_ptr_list(struct ptr_list **);
 extern int ptr_list_size(struct ptr_list *);
@@ -53,13 +54,12 @@ extern int linearize_ptr_list(struct ptr_list *, void **, int);
  * extensions..
  */
 #define add_ptr_list_tag(list,entry,tag) \
-	MKTYPE(*(list), (CHECK_TYPE(*(list),(entry)),__add_ptr_list((struct ptr_list **)(list), (entry), (tag))))
-#define add_ptr_list_notag(list,entry)										\
-	MKTYPE(*(list), (CHECK_TYPE(*(list),(entry)),__add_ptr_list((struct ptr_list **)(list),			\
-								    (void *)((unsigned long)(entry) & ~3UL), 	\
-								    (unsigned long)(entry) & 3)))
-#define add_ptr_list(list,entry) \
-	add_ptr_list_tag(list,entry,0)
+	MKTYPE(*(list), (CHECK_TYPE(*(list),(entry)),__add_ptr_list_tag((struct ptr_list **)(list), (entry), (tag))))
+#define add_ptr_list(list,entry)	\
+	MKTYPE(*(list), (CHECK_TYPE(*(list),(entry)),__add_ptr_list((struct ptr_list **)(list),	(entry))))
+#define add_ptr_list_notag(list,entry) \
+	add_ptr_list(list, entry)
+
 #define free_ptr_list(list) \
 	do { VRFY_PTR_LIST(*(list)); __free_ptr_list((struct ptr_list **)(list)); } while (0)
 
-- 
2.17.1

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux