From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id BE5903A4B83A for ; Thu, 12 Nov 2020 15:04:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BE5903A4B83A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-107-ALEW2oYsNgi4QnwgOqGeDg-1; Thu, 12 Nov 2020 10:04:51 -0500 X-MC-Unique: ALEW2oYsNgi4QnwgOqGeDg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7035710866A8 for ; Thu, 12 Nov 2020 15:04:50 +0000 (UTC) Received: from hostfoo.redhat.com (ovpn-113-115.ams2.redhat.com [10.36.113.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71CB755766; Thu, 12 Nov 2020 15:04:49 +0000 (UTC) From: =?UTF-8?q?Timm=20B=C3=A4der?= To: elfutils-devel@sourceware.org Subject: [PATCH 12/14] segment_report_module: Unify d32/d64 loops Date: Thu, 12 Nov 2020 16:04:10 +0100 Message-Id: <20201112150412.2137981-13-tbaeder@redhat.com> In-Reply-To: <20201112150412.2137981-1-tbaeder@redhat.com> References: <20201112150412.2137981-1-tbaeder@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Nov 2020 15:04:54 -0000 Just like we did before, use only one loop here and check for 32/64 bit in the loop body. This way we only have one call site for consider_dyn Signed-off-by: Timm Bäder --- libdwfl/dwfl_segment_report_module.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c index bcf69fe7..7c97784f 100644 --- a/libdwfl/dwfl_segment_report_module.c +++ b/libdwfl/dwfl_segment_report_module.c @@ -838,20 +838,20 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, xlateto.d_buf = dyns; xlateto.d_size = dyn_filesz; - if (ei_class == ELFCLASS32) - { - if (elf32_xlatetom (&xlateto, &xlatefrom, ei_data) != NULL) - for (size_t i = 0; i < dyn_filesz / sizeof (Elf32_Dyn); ++i) - if (consider_dyn (d32[i].d_tag, d32[i].d_un.d_val)) - break; - } - else - { - if (elf64_xlatetom (&xlateto, &xlatefrom, ei_data) != NULL) - for (size_t i = 0; i < dyn_filesz / sizeof (Elf64_Dyn); ++i) - if (consider_dyn (d64[i].d_tag, d64[i].d_un.d_val)) - break; - } + bool is32 = (ei_class == ELFCLASS32); + if ((is32 && elf32_xlatetom (&xlateto, &xlatefrom, ei_data) != NULL) + || (!is32 && elf64_xlatetom (&xlateto, &xlatefrom, ei_data) != NULL)) + { + size_t n = is32 ? (dyn_filesz / sizeof (Elf32_Dyn)) : (dyn_filesz / sizeof (Elf64_Dyn)); + for (size_t i = 0; i < n; ++i) + { + GElf_Sxword tag = is32 ? d32[i].d_tag : d64[i].d_tag; + GElf_Xword val = is32 ? d32[i].d_un.d_val : d64[i].d_un.d_val; + + if (consider_dyn (tag, val)) + break; + } + } free (dyns); } finish_portion (dwfl, memory_callback, memory_callback_arg, &dyn_data, &dyn_data_size); -- 2.26.2