From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id FU8hN9jMTGIdFwAAWB0awg (envelope-from ) for ; Tue, 05 Apr 2022 19:12:24 -0400 Received: by simark.ca (Postfix, from userid 112) id C9B971F344; Tue, 5 Apr 2022 19:12:24 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 44EB61E150 for ; Tue, 5 Apr 2022 19:12:24 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2FCFD3858C2D for ; Tue, 5 Apr 2022 23:12:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2FCFD3858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1649200343; bh=UhEAG4pbq5XUnBRctCvVRCtgFXX81lenzHHL+CwHuEA=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=FKY6C0oj60Zq4d1EGe8YreYksBDwfxNdoc5RQjmbOQk+HM5xRnH9jQJ8xO2f9ioPb WI5BKXU/ONA4nuagqUuMvG6uTcPdY0fMcxGn9xBYrwel8FMXeZ+NNcnDb+0M8ENWgk Nh1174gh0zFtwNHQoUOpgrhOYEXIoly6sPUTLgo8= Received: from lndn.lancelotsix.com (vps-42846194.vps.ovh.net [IPv6:2001:41d0:801:2000::2400]) by sourceware.org (Postfix) with ESMTPS id DED753858D37 for ; Tue, 5 Apr 2022 23:12:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DED753858D37 Received: from ubuntu (unknown [IPv6:2a02:390:9086::635]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id BA44A818C2; Tue, 5 Apr 2022 23:12:02 +0000 (UTC) Date: Tue, 5 Apr 2022 23:11:53 +0000 To: Andrew Burgess Subject: Re: [PATCH 11/16] gdb: remove reggroup_next and reggroup_prev Message-ID: <20220405231144.kzqrzl2hmo32ifbv@ubuntu> References: <439ec4ff1564f25ed90d70b0bd50ff55ccbec539.1648760270.git.aburgess@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <439ec4ff1564f25ed90d70b0bd50ff55ccbec539.1648760270.git.aburgess@redhat.com> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (lndn.lancelotsix.com [0.0.0.0]); Tue, 05 Apr 2022 23:12:02 +0000 (UTC) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Lancelot SIX via Gdb-patches Reply-To: Lancelot SIX Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" > diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c > index b968947fa1c..65ec8241370 100644 > --- a/gdb/tui/tui-regs.c > +++ b/gdb/tui/tui-regs.c > @@ -523,10 +523,21 @@ tui_data_item_window::rerender (WINDOW *handle, int field_width) > static const reggroup * > tui_reg_next (const reggroup *current_group, struct gdbarch *gdbarch) > { > - const reggroup *group = reggroup_next (gdbarch, current_group); > - if (group == NULL) > - group = reggroup_next (gdbarch, NULL); > - return group; > + const std::vector &groups = gdbarch_reggroups (gdbarch); > + > + if (current_group != nullptr) > + for (int i = 0; i < groups.size (); ++i) > + { > + if (groups[i] == current_group) > + { > + if (i + 1 < groups.size ()) > + return groups[i + 1]; > + else > + return groups.front (); > + } > + } > + > + return groups.front (); > } > > /* Helper for "tui reg prev", wraps a call to REGGROUP_PREV, but adds wrap > @@ -538,10 +549,27 @@ tui_reg_next (const reggroup *current_group, struct gdbarch *gdbarch) > static const reggroup * > tui_reg_prev (const reggroup *current_group, struct gdbarch *gdbarch) > { > - const reggroup *group = reggroup_prev (gdbarch, current_group); > - if (group == NULL) > - group = reggroup_prev (gdbarch, NULL); > - return group; > + const std::vector &groups = gdbarch_reggroups (gdbarch); > + > + if (current_group != nullptr) > + { > + /* Iterate backwards. */ > + for (auto iter = groups.rbegin (); > + iter != groups.rend (); > + ++iter) > + { > + if (*iter == current_group) > + { > + ++iter; > + if (iter == groups.rend ()) > + return groups.back (); > + else > + return *iter; > + } > + } > + } > + > + return groups.back (); > } > Hi, It looks strange to have tui_reg_next implemented using iteration over indexes while tui_reg_prev is implemented using iterators. It looks to me that both cases are similar enough to use a similar pattern. Also, the for loop can probably be replaced by a call to std::find which the overall thing more concise: static const reggroup * tui_reg_prev (const reggroup *current_group, struct gdbarch *gdbarch) { const std::vector &groups = gdbarch_reggroups (gdbarch); auto it = std::find (groups.rbegin (), groups.rend (), current_group); it++; if (it >= groups.rend ()) return groups.back (); return *it; } and something similar for tui_reg_next, changing rbegin/rend with begin/end and .back with .front. WDYT? Best, Lancelot.