From patchwork Fri Jul 18 19:27:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 2114 Received: (qmail 28727 invoked by alias); 18 Jul 2014 19:27:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 28612 invoked by uid 89); 18 Jul 2014 19:27:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 18 Jul 2014 19:27:20 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6IJRJm2028245 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 18 Jul 2014 15:27:19 -0400 Received: from barimba.redhat.com (ovpn-113-27.phx2.redhat.com [10.3.113.27]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6IJRHfu019114; Fri, 18 Jul 2014 15:27:18 -0400 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/4] simplify target_is_pushed Date: Fri, 18 Jul 2014 13:27:13 -0600 Message-Id: <1405711635-1102-3-git-send-email-tromey@redhat.com> In-Reply-To: <1405711635-1102-1-git-send-email-tromey@redhat.com> References: <1405711635-1102-1-git-send-email-tromey@redhat.com> 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 * target.c (target_is_pushed): Simplify. --- gdb/ChangeLog | 4 ++++ gdb/target.c | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) 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;