Mesa (master): exec_list: Add a function to give the length of a list.

Matt Turner mattst88 at kemper.freedesktop.org
Tue Jul 15 18:19:16 UTC 2014


Module: Mesa
Branch: master
Commit: 7b0f69225afb362ec2681d9b36eae2d035b10c00
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7b0f69225afb362ec2681d9b36eae2d035b10c00

Author: Connor Abbott <cwabbott0 at gmail.com>
Date:   Tue Jul  8 12:20:59 2014 -0700

exec_list: Add a function to give the length of a list.

v2 [mattst88]: Remove trailing whitespace. Rename get_size to length.
               Mark as const.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com> [v1]
Reviewed-by: Matt Turner <mattst88 at gmail.com>
Signed-off-by: Connor Abbott <connor.abbott at intel.com>

---

 src/glsl/list.h |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/glsl/list.h b/src/glsl/list.h
index 66028f6..3cc48ce 100644
--- a/src/glsl/list.h
+++ b/src/glsl/list.h
@@ -325,6 +325,8 @@ struct exec_list {
    const exec_node *get_tail() const;
    exec_node *get_tail();
 
+   unsigned length() const;
+
    void push_head(exec_node *n);
    void push_tail(exec_node *n);
    void push_degenerate_list_at_head(exec_node *n);
@@ -405,6 +407,19 @@ exec_list_get_tail(struct exec_list *list)
    return !exec_list_is_empty(list) ? list->tail_pred : NULL;
 }
 
+static inline unsigned
+exec_list_length(const struct exec_list *list)
+{
+   unsigned size = 0;
+
+   for (struct exec_node *node = list->head; node->next != NULL;
+	node = node->next) {
+      size++;
+   }
+
+   return size;
+}
+
 static inline void
 exec_list_push_head(struct exec_list *list, struct exec_node *n)
 {
@@ -537,6 +552,11 @@ inline exec_node *exec_list::get_tail()
    return exec_list_get_tail(this);
 }
 
+inline unsigned exec_list::length() const
+{
+   return exec_list_length(this);
+}
+
 inline void exec_list::push_head(exec_node *n)
 {
    exec_list_push_head(this, n);




More information about the mesa-commit mailing list