From patchwork Fri Sep 10 11:23:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 44921 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 54154384A896 for ; Fri, 10 Sep 2021 11:23:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54154384A896 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631273021; bh=jSjTt9DROI8DBTjePeuuoAWfHdLTvhoik79YhJPTrNo=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=wGLXikx4xdcbTxNdHDCLFlpwXzHVypkG5IcrlYWXAglfGV+Vf748sUYxcondjfw+a i6uHJmFSvpF+yQ4T+42v7DWrGFD0PfcstSRegzaYxXpoFFZCBW3bl8AOPDMwoyaOqP SJ8L01Exy1qd5Rn1FDkCzaa/5aWEOzEDzbvlxyo4= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by sourceware.org (Postfix) with ESMTPS id 1BAF83858C39 for ; Fri, 10 Sep 2021 11:23:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1BAF83858C39 Received: by mail-qk1-x74a.google.com with SMTP id h10-20020a05620a284a00b003d30e8c8cb5so4418796qkp.11 for ; Fri, 10 Sep 2021 04:23:34 -0700 (PDT) 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=jSjTt9DROI8DBTjePeuuoAWfHdLTvhoik79YhJPTrNo=; b=Wpn0DXNX11cW1uEsGbWSOqqKYa7wVSkhCGEjeP446msXEm6LKiebCTcHRj6O9M4b+j yZUcdQrMqGixbK2Uhj3i3VLdOyXk1WZWDru8pl101oaUPRygICrBXwNduahOQIeDSYW/ 4GmruCIAlrz7NoPjyVN6JKvPFqZPxE7xQ2V2goG56Bkeq28yZJcLKIMOv0/UsPLqeLXu hDQS4lQHPf2NQKgRnSbCjwJQoHKVZ/goeN60D0E/3wb9okCVz8dDUWXnZ0iud5NqWbua sIsweu0jCKsMXlQLOaCk+Yjp2r6x5bE67dzQAXRewtvmOeK1Oq7EIXmlzxH7KdLrN8nz rB2g== X-Gm-Message-State: AOAM531oo/72TeJouZf24eXhsVsMpVMv2dbPsdlOeWFkKzWMfa5I3d+s C78aRKl1NnxQi1gGo+cTarssWy7ot1Y2Px3Tb6X7wKSTao10Z+qO3+lU7SAea2nsDk+XihUvWKB 6aOC9nhLSSECk1bDYyRPeTFkKrUgvvhmRI75WEuFkXSkSRwdO4fkNE3dfyGDDKeHx0Wo/tQA= X-Google-Smtp-Source: ABdhPJzTVtiPMKVihLLsSEimUdJs2ELjzgm58/S3kVkwes7OGpawz2SCdn2qeiCu6JyN7DZMaSjuAnGqb59CCg== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:fe2b:14b7:895d:9020]) (user=gprocida job=sendgmr) by 2002:a0c:c290:: with SMTP id b16mr7806769qvi.65.1631273013750; Fri, 10 Sep 2021 04:23:33 -0700 (PDT) Date: Fri, 10 Sep 2021 12:23:23 +0100 In-Reply-To: <20210910112325.806676-1-gprocida@google.com> Message-Id: <20210910112325.806676-3-gprocida@google.com> Mime-Version: 1.0 References: <20210910112325.806676-1-gprocida@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH 2/4] abg-writer: refactor recording of unemitted types To: libabigail@sourceware.org X-Spam-Status: No, score=-22.4 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" The code fragment if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last)) referenced_types_to_emit.insert(*i); appears 5 times. This commit inlines the insertion into the helper function which is also renamed. * src/abg-writer.cc (referenced_type_should_be_emitted): Replaced by record_unemitted_type. (record_unemitted_type): Replacement function that also takes care of inserting the type into the set. (write_translation_unit): Replace calls to referenced_type_should_be_emitted and inserts with calls to record_unemitted_type. Signed-off-by: Giuliano Procida --- src/abg-writer.cc | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index d23f4fd6..795ca685 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -2248,10 +2248,12 @@ write_canonical_types_of_scope(const scope_decl &scope, } /// Test if a type referenced in a given translation unit should be -/// emitted or not. +/// emitted and record it if so. /// /// This is a subroutine of @ref write_translation_unit. /// +/// @param types the set of types to update. +/// /// @param t the type to consider. /// /// @param ctxt the write context to consider. @@ -2260,20 +2262,18 @@ write_canonical_types_of_scope(const scope_decl &scope, /// /// @param tu_is_last true if @p tu is the last translation unit being /// emitted. -/// -/// @return true iff @p t is to be emitted. -static bool -referenced_type_should_be_emitted(const type_base *t, - const write_context& ctxt, - const translation_unit& tu, - bool tu_is_last) +static void +record_unemitted_type(type_ptr_set_type& types, + const type_base *t, + const write_context& ctxt, + const translation_unit& tu, + bool tu_is_last) { if ((tu_is_last || t->get_translation_unit()->get_absolute_path() == tu.get_absolute_path()) && !ctxt.type_is_emitted(t) && !ctxt.decl_only_type_is_emitted(t)) - return true; - return false; + types.insert(t); } /// Serialize a translation unit to an output stream. @@ -2389,22 +2389,19 @@ write_translation_unit(write_context& ctxt, ctxt.get_referenced_types().begin(); i != ctxt.get_referenced_types().end(); ++i) - if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last)) - referenced_types_to_emit.insert(*i); + record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last); for (fn_type_ptr_set_type::const_iterator i = ctxt.get_referenced_function_types().begin(); i != ctxt.get_referenced_function_types().end(); ++i) - if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last)) - referenced_types_to_emit.insert(*i); + record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last); for (type_ptr_set_type::const_iterator i = ctxt.get_referenced_non_canonical_types().begin(); i != ctxt.get_referenced_non_canonical_types().end(); ++i) - if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last)) - referenced_types_to_emit.insert(*i); + record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last); // Ok, now let's emit the referenced type for good. while (!referenced_types_to_emit.empty()) @@ -2459,15 +2456,13 @@ write_translation_unit(write_context& ctxt, ctxt.get_referenced_types().begin(); i != ctxt.get_referenced_types().end(); ++i) - if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last)) - referenced_types_to_emit.insert(*i); + record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last); for (type_ptr_set_type::const_iterator i = ctxt.get_referenced_non_canonical_types().begin(); i != ctxt.get_referenced_non_canonical_types().end(); ++i) - if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last)) - referenced_types_to_emit.insert(*i); + record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last); } // Now handle all function types that were not only referenced by