]> wimlib.net Git - wimlib/commitdiff
Remove unnecessary argument to hlist iteration macros
authorEric Biggers <ebiggers3@gmail.com>
Sat, 11 Apr 2015 14:38:58 +0000 (09:38 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 11 Apr 2015 14:44:59 +0000 (09:44 -0500)
include/wimlib/list.h
src/blob_table.c
src/inode_fixup.c
src/inode_table.c
src/solid.c
src/write.c

index 5e940cc111057d5ff725ec591bea376bc272d201..f59e113c994c52d217f3c9807af4b20c474446ec 100644 (file)
@@ -9,35 +9,18 @@
 #include <stdbool.h>
 #include <stddef.h>
 
-struct list_head {
-       struct list_head *next, *prev;
-};
-struct hlist_head {
-       struct hlist_node *first;
-};
+/* Simple doubly linked list implementation.  */
 
-struct hlist_node {
-       struct hlist_node *next, **pprev;
+struct list_head {
+       struct list_head *next;
+       struct list_head *prev;
 };
 
-/*
- * Simple doubly linked list implementation.
- *
- * Some of the internal functions ("__xxx") are useful when
- * manipulating whole lists rather than single entries, as
- * sometimes we already know the next/prev entries and we can
- * generate better code by using them directly rather than
- * using the generic single-entry routines.
- */
 
 #define LIST_HEAD_INIT(name) { &(name), &(name) }
 
-#ifdef LIST_HEAD /* BSD sys/queue.h defines this... */
-#  undef LIST_HEAD
-#endif
-
-#define LIST_HEAD(name) \
-       struct list_head name = LIST_HEAD_INIT(name)
+#undef LIST_HEAD /* BSD sys/queue.h defines this... */
+#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
 
 static inline void
 INIT_LIST_HEAD(struct list_head *list)
@@ -133,8 +116,7 @@ list_empty(const struct list_head *head)
 
 static inline void
 __list_splice(const struct list_head *list,
-             struct list_head *prev,
-             struct list_head *next)
+             struct list_head *prev, struct list_head *next)
 {
        struct list_head *first = list->next;
        struct list_head *last = list->prev;
@@ -310,7 +292,20 @@ list_splice_tail(struct list_head *list, struct list_head *head)
  * You lose the ability to access the tail in O(1).
  */
 
-#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
+struct hlist_head {
+       struct hlist_node *first;
+};
+
+struct hlist_node {
+       struct hlist_node *next;
+       struct hlist_node **pprev;
+};
+
+static inline void
+INIT_HLIST_HEAD(struct hlist_head *h)
+{
+       h->first = NULL;
+}
 
 static inline bool
 hlist_unhashed(const struct hlist_node *h)
@@ -347,31 +342,32 @@ hlist_add_head(struct hlist_node *n, struct hlist_head *h)
 
 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
 
+#define hlist_entry_safe(ptr, type, member) \
+       ({ typeof(ptr) ____ptr = (ptr); \
+          ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
+       })
+
 /**
  * hlist_for_each_entry        - iterate over list of given type
- * @tpos:      the type * to use as a loop cursor.
- * @pos:       the &struct hlist_node to use as a loop cursor.
+ * @pos:       the type * to use as a loop cursor.
  * @head:      the head for your list.
  * @member:    the name of the hlist_node within the struct.
  */
-#define hlist_for_each_entry(tpos, pos, head, member)                   \
-       for (pos = (head)->first;                                        \
-            pos &&                                                      \
-               ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
-            pos = pos->next)
+#define hlist_for_each_entry(pos, head, member)                                \
+       for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
+            pos;                                                       \
+            pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
 
 /**
  * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
- * @tpos:      the type * to use as a loop cursor.
- * @pos:       the &struct hlist_node to use as a loop cursor.
+ * @pos:       the type * to use as a loop cursor.
  * @n:         another &struct hlist_node to use as temporary storage
  * @head:      the head for your list.
  * @member:    the name of the hlist_node within the struct.
  */
-#define hlist_for_each_entry_safe(tpos, pos, n, head, member)           \
-       for (pos = (head)->first;                                        \
-            pos && ({ n = pos->next; 1; }) &&                           \
-               ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
-            pos = n)
+#define hlist_for_each_entry_safe(pos, n, head, member)                \
+       for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\
+            pos && ({ n = pos->member.next; 1; });                     \
+            pos = hlist_entry_safe(n, typeof(*pos), member))
 
 #endif /* _WIMLIB_LIST_H */
index 2d346e3539ecca661b774802a98f046dd7873960..bcccae8ba9ddb1ab96ef362cdab176756dcb375f 100644 (file)
@@ -318,7 +318,7 @@ enlarge_blob_table(struct blob_table *table)
        size_t old_capacity, new_capacity;
        struct hlist_head *old_array, *new_array;
        struct blob_descriptor *blob;
-       struct hlist_node *cur, *tmp;
+       struct hlist_node *tmp;
        size_t i;
 
        old_capacity = table->capacity;
@@ -331,7 +331,7 @@ enlarge_blob_table(struct blob_table *table)
        table->capacity = new_capacity;
 
        for (i = 0; i < old_capacity; i++) {
-               hlist_for_each_entry_safe(blob, cur, tmp, &old_array[i], hash_list) {
+               hlist_for_each_entry_safe(blob, tmp, &old_array[i], hash_list) {
                        hlist_del(&blob->hash_list);
                        blob_table_insert_raw(table, blob);
                }
@@ -366,10 +366,9 @@ lookup_blob(const struct blob_table *table, const u8 *hash)
 {
        size_t i;
        struct blob_descriptor *blob;
-       struct hlist_node *pos;
 
        i = load_size_t_unaligned(hash) % table->capacity;
-       hlist_for_each_entry(blob, pos, &table->array[i], hash_list)
+       hlist_for_each_entry(blob, &table->array[i], hash_list)
                if (hashes_equal(hash, blob->hash))
                        return blob;
        return NULL;
@@ -382,11 +381,11 @@ for_blob_in_table(struct blob_table *table,
                  int (*visitor)(struct blob_descriptor *, void *), void *arg)
 {
        struct blob_descriptor *blob;
-       struct hlist_node *pos, *tmp;
+       struct hlist_node *tmp;
        int ret;
 
        for (size_t i = 0; i < table->capacity; i++) {
-               hlist_for_each_entry_safe(blob, pos, tmp, &table->array[i],
+               hlist_for_each_entry_safe(blob, tmp, &table->array[i],
                                          hash_list)
                {
                        ret = visitor(blob, arg);
index 6929cf7a417cf85185842a7c7f3da0f54e2ddfab..5e8a58afaa8cf75e4736bf86112998807adec8c8 100644 (file)
@@ -65,7 +65,6 @@ inode_table_insert(struct wim_dentry *dentry, void *_params)
        struct wim_inode *d_inode = dentry->d_inode;
        size_t pos;
        struct wim_inode *inode;
-       struct hlist_node *cur;
 
        if (d_inode->i_ino == 0) {
                list_add_tail(&d_inode->i_list, &table->extra_inodes);
@@ -74,7 +73,7 @@ inode_table_insert(struct wim_dentry *dentry, void *_params)
 
        /* Try adding this dentry to an existing inode.  */
        pos = d_inode->i_ino % table->capacity;
-       hlist_for_each_entry(inode, cur, &table->array[pos], i_hlist) {
+       hlist_for_each_entry(inode, &table->array[pos], i_hlist) {
                if (inode->i_ino != d_inode->i_ino) {
                        continue;
                }
index 1a1fba691e930371abbd9d153d681b2ee1179c5e..7c8626f2d1d5e8fdf9d6fb09b10f014db06ce918 100644 (file)
@@ -102,12 +102,11 @@ inode_table_new_dentry(struct wim_inode_table *table, const tchar *name,
                list_add_tail(&dentry->d_inode->i_list, &table->extra_inodes);
        } else {
                size_t pos;
-               struct hlist_node *cur;
 
                /* File that can be hardlinked--- search the table for an
                 * existing inode matching the inode number and device.  */
                pos = hash_u64(hash_u64(ino) + hash_u64(devno)) % table->capacity;
-               hlist_for_each_entry(inode, cur, &table->array[pos], i_hlist) {
+               hlist_for_each_entry(inode, &table->array[pos], i_hlist) {
                        if (inode->i_ino == ino && inode->i_devno == devno) {
                                /* Found; use the existing inode.  */
                                return new_dentry_with_existing_inode(name, inode,
@@ -140,7 +139,7 @@ inode_table_prepare_inode_list(struct wim_inode_table *table,
                               struct list_head *head)
 {
        struct wim_inode *inode, *tmp_inode;
-       struct hlist_node *cur, *tmp;
+       struct hlist_node *tmp;
        u64 cur_ino = 1;
 
        /* Re-assign inode numbers in the existing list to avoid duplicates. */
@@ -150,8 +149,7 @@ inode_table_prepare_inode_list(struct wim_inode_table *table,
        /* Assign inode numbers to the new inodes and move them to the image's
         * inode list. */
        for (size_t i = 0; i < table->capacity; i++) {
-               hlist_for_each_entry_safe(inode, cur, tmp, &table->array[i], i_hlist)
-               {
+               hlist_for_each_entry_safe(inode, tmp, &table->array[i], i_hlist) {
                        inode->i_ino = cur_ino++;
                        inode->i_devno = 0;
                        list_add_tail(&inode->i_list, head);
index ab00b0fa74539987a6fa72a88e3a675223ef37c7..704fb41467e5375030f48d78123c12c154dba38f 100644 (file)
@@ -136,13 +136,12 @@ dentry_fill_in_solid_sort_names(struct wim_dentry *dentry, void *_blob_table)
        const struct wim_inode *inode = dentry->d_inode;
        const u8 *hash;
        struct hlist_head *head;
-       struct hlist_node *cur;
        struct blob_descriptor *blob;
 
        hash = inode_get_hash_of_unnamed_data_stream(inode);
        head = &blob_table->table[load_size_t_unaligned(hash) %
                                  blob_table->capacity];
-       hlist_for_each_entry(blob, cur, head, hash_list_2) {
+       hlist_for_each_entry(blob, head, hash_list_2) {
                if (hashes_equal(hash, blob->hash)) {
                        blob_set_solid_sort_name_from_inode(blob, inode);
                        break;
index 6be215e3e76570bd38aa12fc28afec740911f92f..ef78f9cadfc93e5df4fbb029d1f8e27270b2af3f 100644 (file)
@@ -1834,11 +1834,10 @@ blob_size_table_insert(struct blob_descriptor *blob, void *_tab)
        struct blob_size_table *tab = _tab;
        size_t pos;
        struct blob_descriptor *same_size_blob;
-       struct hlist_node *tmp;
 
        pos = hash_u64(blob->size) % tab->capacity;
        blob->unique_size = 1;
-       hlist_for_each_entry(same_size_blob, tmp, &tab->array[pos], hash_list_2) {
+       hlist_for_each_entry(same_size_blob, &tab->array[pos], hash_list_2) {
                if (same_size_blob->size == blob->size) {
                        blob->unique_size = 0;
                        same_size_blob->unique_size = 0;