From patchwork Fri Jan 21 17:30:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 50324 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A7293857816 for ; Fri, 21 Jan 2022 17:33:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A7293857816 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642786389; bh=n11T76CSEGkIVmM34x0+eUraOsXodMiWJ2L1tmAIHIA=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=yeyqhIdnaNnKetws2w+34R2Q6AciNvypFAuxA/2st09BUBB/SQR1/xPf/n8sWA40j w5MvQygKFukliZoHISIpHdRjnLme/He8cjnTzmCS2VOj0Z6xA6Fkh5tfVMhtFonB1S d8y1CBx8cBy7K2VkWq1FnKD1mY3RjomKZ1fmsFeI= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by sourceware.org (Postfix) with ESMTPS id EF5623858435 for ; Fri, 21 Jan 2022 17:30:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EF5623858435 Received: by mail-ed1-x54a.google.com with SMTP id o25-20020a056402039900b0040631c2a67dso3155229edv.19 for ; Fri, 21 Jan 2022 09:30:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=n11T76CSEGkIVmM34x0+eUraOsXodMiWJ2L1tmAIHIA=; b=aL2IKQ4FHtXKx8B8MCzMMMcLPbG4pe+gxCasUJJaGNUkfSHokX4337THmSOJy9zCfa UcyIkRpGA2cOqX9DQV0P9Z+bJHlWdmb5i0K4hZEhkXjNvipMUpbcZFkj4sOPbmUIjCOf A/TcIRF+DaP/PXq9CwBIIVt7k0gbzB8GhEtWc+1renqYR9NyQy3L4yrDk/SJGc92Nawo K9pxECL8W2kslL7XYWbMi8bY06Bwr/evmONAPyRSvfJTKpIarignia4tJ0AAweuiMcLe PyIpb4KtfDftYb+YyK3K/RUAEVhukENvs87dvAwH+r83X6DhQK8gUuIR/ZKS4QG3/TNH PYRg== X-Gm-Message-State: AOAM5319y4fedZNq4R77sl2Uh0lv2XrWYIX/S1PWOpDkD4tb5B674uGB 8PXT9UhyeIjlTKzpKXeSGoU3S2ZtUz+xgvHMCcG+aJfBRJfdKvVKnu8UEaXkx+CUiTYzuhOIFwS 1FvrlK0Ckaqts2axZuM4Pb/2VK/y9IgGALfqQxZi1P8RFDd0udTSEZ9qRJuhe5/YHvcbPkO4= X-Google-Smtp-Source: ABdhPJxHWceLlR34uiSkO7q4nspaFOjvwa7oF9tXM4TwsAjatlz3OSox+jIhMa3gk/pPA/oDqExO9gM+NX25fw== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:5386:4792:3248:8d5d]) (user=gprocida job=sendgmr) by 2002:a17:906:c0d3:: with SMTP id bn19mr70909ejb.617.1642786221027; Fri, 21 Jan 2022 09:30:21 -0800 (PST) Date: Fri, 21 Jan 2022 17:30:04 +0000 In-Reply-To: <20220121173005.3196387-1-gprocida@google.com> Message-Id: <20220121173005.3196387-4-gprocida@google.com> Mime-Version: 1.0 References: <20220121173005.3196387-1-gprocida@google.com> X-Mailer: git-send-email 2.34.1.703.g22d0c6ccf7-goog Subject: [PATCH 3/4] XML writer: improve slightly emission of top-level declarations To: libabigail@sourceware.org X-Spam-Status: No, score=-21.6 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Giuliano Procida via Libabigail From: Giuliano Procida Reply-To: Giuliano Procida Cc: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" In the loop that emits declarations, the iterator already points to a decl_base_sptr, there is no need to do another dynamic_cast. It is also possible to simplify the loop and its conditionals. There is no change to tests or behaviour. * src/abg-writer.cc (decl_is_emitted): Make decl_base_sptr argument a const reference. (write_translation_unit): Eliminate a typedef and just use a range-for loop without the extra dynamic cast for the non-type case. Use else instead of continue to make it clear there are only two possibilities. Reviewed-by: Matthias Maennich Signed-off-by: Giuliano Procida --- src/abg-writer.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index 53adca24..44959a02 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -733,7 +733,7 @@ public: /// @return true if the decl has already been emitted, false /// otherwise. bool - decl_is_emitted(decl_base_sptr& decl) const + decl_is_emitted(const decl_base_sptr& decl) const { ABG_ASSERT(!is_type(decl)); string repr = get_pretty_representation(decl, true); @@ -2440,12 +2440,11 @@ write_translation_unit(write_context& ctxt, ctxt, indent + c.get_xml_element_indent()); typedef scope_decl::declarations declarations; - typedef declarations::const_iterator const_iterator; - const declarations& d = tu.get_global_scope()->get_sorted_member_decls(); + const declarations& decls = tu.get_global_scope()->get_sorted_member_decls(); - for (const_iterator i = d.begin(); i != d.end(); ++i) + for (const decl_base_sptr& decl : decls) { - if (type_base_sptr t = is_type(*i)) + if (type_base_sptr t = is_type(decl)) { // Emit declaration-only classes that are needed. Some of // these classes can be empty. Those beasts can be classes @@ -2456,13 +2455,12 @@ write_translation_unit(write_context& ctxt, && !ctxt.type_is_emitted(class_type)) write_type(class_type, ctxt, indent + c.get_xml_element_indent()); - continue; } - - if (decl_base_sptr d = is_decl(*i)) - if (ctxt.decl_is_emitted(d)) - continue; - write_decl(*i, ctxt, indent + c.get_xml_element_indent()); + else + { + if (!ctxt.decl_is_emitted(decl)) + write_decl(decl, ctxt, indent + c.get_xml_element_indent()); + } } write_referenced_types(ctxt, tu, indent, is_last);