This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[FYI 2/2] Do not make "prop" field of struct dynamic_prop_list a pointer.


This is something that was discussed during the review of the patch
adding the struct dynamic_prop_list, and eventually postponed for
later...

struct dynamic_prop_list is declared as follow:

    struct dynamic_prop_list
    {
      [...]
      /* The dynamic property itself.  */
      struct dynamic_prop *prop;
      [...]
    };

In this case, the pointer indirection is unnecessary and costing us,
for each dynamic property, the memory needed to store one pointer.
This patch removes this pointer indirection, savin us a tiny bit of
memory, as well as reduces a bit the complexity by removing the need
to allocate memory for the property, as the allocation is now part
of the struct itself.

gdb/ChangeLog:

        * gdbtypes.h (struct dynamic_prop_list) <prop>: Remove
        pointer indirection.
        * gdbtypes.c (get_dyn_prop): Adjust, following change above.
        (add_dyn_prop, copy_dynamic_prop_list): Likewise.

Tested on x86_64-linux and pushed.

Thanks,
-- 
Joel

---
 gdb/ChangeLog  | 7 +++++++
 gdb/gdbtypes.c | 7 +++----
 gdb/gdbtypes.h | 2 +-
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 78ccc8a..43dda55 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
 2015-03-24  Joel Brobecker  <brobecker@adacore.com>
 
+	* gdbtypes.h (struct dynamic_prop_list) <prop>: Remove
+	pointer indirection.
+	* gdbtypes.c (get_dyn_prop): Adjust, following change above.
+	(add_dyn_prop, copy_dynamic_prop_list): Likewise.
+
+2015-03-24  Joel Brobecker  <brobecker@adacore.com>
+
 	* gdbtypes.h (enum dynamic_prop_node_kind) <DYN_PROP_DATA_LOCATION>:
 	Renames DYN_ATTR_DATA_LOCATION.
 	(TYPE_DATA_LOCATION): Use DYN_PROP_DATA_LOCATION instead of
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 19579af..217ec70 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2109,7 +2109,7 @@ get_dyn_prop (enum dynamic_prop_node_kind prop_kind, const struct type *type)
   while (node != NULL)
     {
       if (node->prop_kind == prop_kind)
-        return node->prop;
+        return &node->prop;
       node = node->next;
     }
   return NULL;
@@ -2128,7 +2128,7 @@ add_dyn_prop (enum dynamic_prop_node_kind prop_kind, struct dynamic_prop prop,
   temp = obstack_alloc (&objfile->objfile_obstack,
 			sizeof (struct dynamic_prop_list));
   temp->prop_kind = prop_kind;
-  temp->prop = obstack_copy (&objfile->objfile_obstack, &prop, sizeof (prop));
+  temp->prop = prop;
   temp->next = TYPE_DYN_PROP_LIST (type);
 
   TYPE_DYN_PROP_LIST (type) = temp;
@@ -4279,8 +4279,7 @@ copy_dynamic_prop_list (struct obstack *objfile_obstack,
 
       node_copy = obstack_copy (objfile_obstack, *node_ptr,
 				sizeof (struct dynamic_prop_list));
-      node_copy->prop = obstack_copy (objfile_obstack, (*node_ptr)->prop,
-				      sizeof (struct dynamic_prop));
+      node_copy->prop = (*node_ptr)->prop;
       *node_ptr = node_copy;
 
       node_ptr = &node_copy->next;
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 15d6cd5..883418f 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -449,7 +449,7 @@ struct dynamic_prop_list
   enum dynamic_prop_node_kind prop_kind;
 
   /* The dynamic property itself.  */
-  struct dynamic_prop *prop;
+  struct dynamic_prop prop;
 
   /* A pointer to the next dynamic property.  */
   struct dynamic_prop_list *next;
-- 
1.9.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]