[2/4] simplify target_is_pushed

Message ID 1405711635-1102-3-git-send-email-tromey@redhat.com
State Committed
Headers

Commit Message

Tom Tromey July 18, 2014, 7:27 p.m. UTC
  While working on target_is_pushed, I noticed that it is written in a
strange way.  The code currently keeps an extra indirection, where a
simple linked list traversal is all that is needed.  It seems likely
this was done by copying and pasting other code.  However, there is no
reason to do this and the more obvious code is simpler to reason
about.  So, this patch change the implementation.

2014-07-18  Tom Tromey  <tromey@redhat.com>

	* target.c (target_is_pushed): Simplify.
---
 gdb/ChangeLog | 4 ++++
 gdb/target.c  | 6 +++---
 2 files changed, 7 insertions(+), 3 deletions(-)
  

Comments

Joel Brobecker July 29, 2014, 12:47 p.m. UTC | #1
> While working on target_is_pushed, I noticed that it is written in a
> strange way.  The code currently keeps an extra indirection, where a
> simple linked list traversal is all that is needed.  It seems likely
> this was done by copying and pasting other code.  However, there is no
> reason to do this and the more obvious code is simpler to reason
> about.  So, this patch change the implementation.
> 
> 2014-07-18  Tom Tromey  <tromey@redhat.com>
> 
> 	* target.c (target_is_pushed): Simplify.

Indeed. It looks like this one could go in on its own...
  
Tom Tromey July 29, 2014, 2:51 p.m. UTC | #2
>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:

>> 2014-07-18  Tom Tromey  <tromey@redhat.com>
>> 
>> * target.c (target_is_pushed): Simplify.

Joel> Indeed. It looks like this one could go in on its own...

Yeah.  I'll push this one soon.  Thanks.

Tom
  

Patch

diff --git a/gdb/target.c b/gdb/target.c
index b9310cf..3d28f85 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -654,7 +654,7 @@  pop_all_targets (void)
 int
 target_is_pushed (struct target_ops *t)
 {
-  struct target_ops **cur;
+  struct target_ops *cur;
 
   /* Check magic number.  If wrong, it probably means someone changed
      the struct definition, but not all the places that initialize one.  */
@@ -667,8 +667,8 @@  target_is_pushed (struct target_ops *t)
 		      _("failed internal consistency check"));
     }
 
-  for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
-    if (*cur == t)
+  for (cur = target_stack; cur != NULL; cur = cur->beneath)
+    if (cur == t)
       return 1;
 
   return 0;