From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OOeIIBiETWIzMgAAWB0awg (envelope-from ) for ; Wed, 06 Apr 2022 08:14:16 -0400 Received: by simark.ca (Postfix, from userid 112) id 82AA91F344; Wed, 6 Apr 2022 08:14:16 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.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 E97361E787 for ; Wed, 6 Apr 2022 08:14:15 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E6753858C27 for ; Wed, 6 Apr 2022 12:14:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E6753858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1649247255; bh=0L8gAFQKD8ZSmzd6w8ytpLBxdFkgMbTgfyerHjBjFn4=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=c9aLzyV6QFaBY1u9B3tGnc+zIGeZlIfexhaq28xE+mn6oRGky2UeLtt4MCJQh6UA7 L+SJ9uZtLjpCSKs94dCf0tB/EBzc0/8yijPHWV4f+pQcpUOQ8s7EdNJgZOx0oCpXm4 YcmzPzMcaOQAgGZHdWOTfIlWRlBdjqHC1vbA6nmw= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id DD6E8385842B for ; Wed, 6 Apr 2022 12:06:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DD6E8385842B Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-PXB5I1uLPEyBKKDGZ2g_BQ-1; Wed, 06 Apr 2022 08:06:03 -0400 X-MC-Unique: PXB5I1uLPEyBKKDGZ2g_BQ-1 Received: by mail-wr1-f72.google.com with SMTP id r16-20020adfbb10000000b002060d469943so427784wrg.4 for ; Wed, 06 Apr 2022 05:06:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=0L8gAFQKD8ZSmzd6w8ytpLBxdFkgMbTgfyerHjBjFn4=; b=vOTP0jFerHoeiEFRq8ijMzWrM5/HLM1IaF1ThRp8RqdVuLwn5M6OyzLpOywvt6+47c kc2mbDStV9lTannif//2efR8BCpLsTyOpkUJaBXQjTZ0BmxKsKz1cPY2PRG6w87rXZik 3iNjV7xkKwLPJdX24t7fRw14KOS38g+14ANCYzTfZ63Wgvr9mO0GuczfnW/m/2y9eP++ pqmC//z/rvBqf8sLfX8vMP76VyTYNSFWOooZj/Rl/0bBCPescWmjj/3LYPL3LTJ2sjeA nj1xtETNWsYd0vJGMqGdeuHcowv/KiQLk1+iRJnW4GZGQSrFF8jt4Nf8n65jXXJOcl79 rHHA== X-Gm-Message-State: AOAM530Ox03jbZDyq87e0iiiOLwRTk2YNq9AZUf2IrQIV19rraj3og4T j8I2ZxWBeQac5ZaJ8eFeS6kgllppMMuaaWNdfnIi9TVHjPJrgwX5YdSVougpw919wT5f58chIE0 Q9qrc9qHrE8KmVTVOczZ4QQ== X-Received: by 2002:a05:6000:18a8:b0:203:eb58:9733 with SMTP id b8-20020a05600018a800b00203eb589733mr6375167wri.151.1649246761988; Wed, 06 Apr 2022 05:06:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyj9L5Fu33P+EFkm4rkAjW6tFldiVcs6vakC6ebgfXC0Fvf9nBJqBAv6BYN1x7aaKiE3GrAwQ== X-Received: by 2002:a05:6000:18a8:b0:203:eb58:9733 with SMTP id b8-20020a05600018a800b00203eb589733mr6375153wri.151.1649246761799; Wed, 06 Apr 2022 05:06:01 -0700 (PDT) Received: from localhost (host86-169-131-113.range86-169.btcentralplus.com. [86.169.131.113]) by smtp.gmail.com with ESMTPSA id f11-20020a7bcc0b000000b0037e0c362b6dsm4769100wmh.31.2022.04.06.05.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:06:01 -0700 (PDT) To: Lancelot SIX Subject: Re: [PATCH 11/16] gdb: remove reggroup_next and reggroup_prev In-Reply-To: <20220405231144.kzqrzl2hmo32ifbv@ubuntu> References: <439ec4ff1564f25ed90d70b0bd50ff55ccbec539.1648760270.git.aburgess@redhat.com> <20220405231144.kzqrzl2hmo32ifbv@ubuntu> Date: Wed, 06 Apr 2022 13:06:00 +0100 Message-ID: <87mtgy76xj.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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: Andrew Burgess via Gdb-patches Reply-To: Andrew Burgess Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Lancelot SIX via Gdb-patches writes: >> 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. That looks excellent. Thanks. I've included this change (to both _next and _prev) in the v2 series I just posted. Thanks, Andrew