From bb9faf844fcacfe2f93df9ec9e92ce4d03f52dcb Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 25 Nov 2004 16:46:58 -0700 Subject: [PATCH] helper function cleanup: separate delete/replace list entries. --- lib.c | 25 +++++++++++++++++++------ lib.h | 8 ++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib.c b/lib.c index 9f4d99f8..1f944a10 100644 --- a/lib.c +++ b/lib.c @@ -324,17 +324,30 @@ void **add_ptr_list(struct ptr_list **listp, void *ptr) return ret; } -int replace_ptr_list(struct ptr_list *head, void *old_ptr, void *new_ptr) +int delete_ptr_list_entry(struct ptr_list **list, void *entry) { int count = 0; void *ptr; - FOR_EACH_PTR(head, ptr) { + FOR_EACH_PTR(*list, ptr) { + if (ptr == entry) { + DELETE_CURRENT_PTR(ptr); + count++; + } + } END_FOR_EACH_PTR(ptr); + if (count) + PACK_PTR_LIST(list); + return count; +} + +int replace_ptr_list_entry(struct ptr_list **list, void *old_ptr, void *new_ptr) +{ + int count = 0; + void *ptr; + + FOR_EACH_PTR(*list, ptr) { if (ptr==old_ptr) { - if (new_ptr) - REPLACE_CURRENT_PTR(ptr, new_ptr); - else - DELETE_CURRENT_PTR(ptr); + REPLACE_CURRENT_PTR(ptr, new_ptr); count ++; } }END_FOR_EACH_PTR(ptr); diff --git a/lib.h b/lib.h index ef1b6571..a2917885 100644 --- a/lib.h +++ b/lib.h @@ -101,7 +101,8 @@ struct ptr_list { #define ptr_list_empty(x) ((x) == NULL) void * delete_ptr_list_last(struct ptr_list **head); -int replace_ptr_list(struct ptr_list *head, void *old_ptr, void *new_ptr); +int delete_ptr_list_entry(struct ptr_list **, void *); +int replace_ptr_list_entry(struct ptr_list **, void *old, void *new); extern void sort_list(struct ptr_list **, int (*)(const void *, const void *)); extern void **add_ptr_list(struct ptr_list **, void *); @@ -205,11 +206,6 @@ static inline pseudo_t first_pseudo(struct pseudo_list *head) return first_ptr_list((struct ptr_list *)head); } -static inline int replace_basic_block_list(struct basic_block_list *head, struct basic_block *from, struct basic_block *to) -{ - return replace_ptr_list((struct ptr_list *)head, (void*)from, (void*)to); -} - static inline void concat_symbol_list(struct symbol_list *from, struct symbol_list **to) { concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to); -- 2.11.4.GIT