aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linearize.h
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-07-05 11:34:04 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-07-25 15:16:19 +0200
commit979a731fccdad2000a19c59f5f65bfb14e025154 (patch)
tree4e4206fdf4658efe4cb94b26b985dd1c434cfa5f /linearize.h
parent5846f394881cedf7742415be899e74fdbb40e6a0 (diff)
downloadsparse-dev-979a731fccdad2000a19c59f5f65bfb14e025154.tar.gz
add ptr_list_empty()
Sometimes we need to know if a list is empty, for example, in order to determine if a pseudo has some users or not. Currently, this is done using ptr_list_size(), which always walks the whole list but the needed answer can be returned as soon as it's known that the list contains at least one element. Add the helper ptr_list_empty() and use it for has_users(). This gives a speedup up to 18% on some pathological workloads. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'linearize.h')
-rw-r--r--linearize.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/linearize.h b/linearize.h
index 092e1ac2..de42e718 100644
--- a/linearize.h
+++ b/linearize.h
@@ -333,9 +333,14 @@ static inline int pseudo_user_list_size(struct pseudo_user_list *list)
return ptr_list_size((struct ptr_list *)list);
}
+static inline bool pseudo_user_list_empty(struct pseudo_user_list *list)
+{
+ return ptr_list_empty((struct ptr_list *)list);
+}
+
static inline int has_users(pseudo_t p)
{
- return pseudo_user_list_size(p->users) != 0;
+ return !pseudo_user_list_empty(p->users);
}
static inline struct pseudo_user *alloc_pseudo_user(struct instruction *insn, pseudo_t *pp)