From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <3r-3qYQgKCkwu352qwrou22uzs.q20zwpopwuowz6285qsAo5s.25u@flex--gprocida.bounces.google.com> Received: from mail-ej1-x64a.google.com (mail-ej1-x64a.google.com [IPv6:2a00:1450:4864:20::64a]) by sourceware.org (Postfix) with ESMTPS id 77843385781E for ; Fri, 21 Jan 2022 17:30:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 77843385781E Received: by mail-ej1-x64a.google.com with SMTP id o4-20020a170906768400b006a981625756so333533ejm.0 for ; Fri, 21 Jan 2022 09:30:24 -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=GpPM95pvOwLmU+TUlLj5FWclMV4BrOvVunGDSpCdeSM=; b=OZBTSi/EreVM+LdTo0/WxkHHmzdXvBNJ+peptpK9S6LRM//3imenbGR+0H2NZfMwBZ s/a+yHxXv0NNXRU0qz7TBRnOdwqZ6dDH/YrQdB3MIMFebV5f5RhDqDewl2IBfKDLOTbQ TMHXDV1IXe9rD+IHI6RA79sQ5dYe0hyxaa1lRUsvz0roq+jM2vA8UsLSlhY1h1dS/HN+ Iog4BXnGU+A9Mixk10LKrnrIL7mtuleBvPVcn6ZA3V+T1k7BlhS/lKgzG4Se5vzA8n4x i5NniYdJNR7MjYNDFVSKJQAoVfddw1y0Mx4LmfvtDrksBz+U/K95YbWotxZaFH7+T1mL THXQ== X-Gm-Message-State: AOAM530xmvsUxG3dNWKxcNtzqANrCevyuiz8N9wAoBRhcXhUiUMIhLoq IjacBRwFV44G71q720YP2lOwLgkISOsXFCObwpNQ4PrFpIrUX7zevKEouXgYGcS/z3N3qBnVbhc DsR45VOjU4xp7i4nfDO6aP5hUxZTHrzfm/Qhl+aXuKfFCeVWAThsev7QKqj54FiiOdlmCaDw= X-Google-Smtp-Source: ABdhPJzKyyDpNbDmUqMDGwPQEwYvT5nZh8iI+UnJRNw3JWxdUKCpTGtg3qpcjrWiH3AWm/5L0weFuORJ30olMQ== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:5386:4792:3248:8d5d]) (user=gprocida job=sendgmr) by 2002:a05:6402:40d0:: with SMTP id z16mr5264153edb.68.1642786223499; Fri, 21 Jan 2022 09:30:23 -0800 (PST) Date: Fri, 21 Jan 2022 17:30:05 +0000 In-Reply-To: <20220121173005.3196387-1-gprocida@google.com> Message-Id: <20220121173005.3196387-5-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 4/4] XML writer: do not create extra temporary referenced type shared_ptr From: Giuliano Procida To: libabigail@sourceware.org Cc: dodji@seketeli.org, kernel-team@android.com, gprocida@google.com, maennich@google.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-21.9 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-List-Received-Date: Fri, 21 Jan 2022 17:30:25 -0000 In the loop of write_referenced_types temporary shared_ptr objects are created. In the case of a declaration, two shared_ptrs are created. It is possible to code this so only one object is created. This is a small optimisation with no change to tests or behaviour. * src/abg-writer.cc (write_referenced_types): Create temporary shared_ptr objects within each conditional branch instead of outside the conditionals and within one of the branches. Reviewed-by: Matthias Maennich Signed-off-by: Giuliano Procida --- src/abg-writer.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index 44959a02..76c71a0c 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -2321,18 +2321,21 @@ write_referenced_types(write_context & ctxt, { // We handle types which have declarations *and* function // types here. - type_base_sptr t(*i, noop_deleter()); + type_base* t = *i; if (!ctxt.type_is_emitted(t)) { - if (decl_base* d = get_type_declaration(*i)) + if (decl_base* d = get_type_declaration(t)) { decl_base_sptr decl(d, noop_deleter()); write_decl_in_scope(decl, ctxt, indent + c.get_xml_element_indent()); } - else if (function_type_sptr fn_type = is_function_type(t)) - write_function_type(fn_type, ctxt, - indent + c.get_xml_element_indent()); + else if (function_type* f = is_function_type(t)) + { + function_type_sptr fn_type(f, noop_deleter()); + write_function_type(fn_type, ctxt, + indent + c.get_xml_element_indent()); + } else ABG_ASSERT_NOT_REACHED; } -- 2.34.1.703.g22d0c6ccf7-goog