From patchwork Wed Nov 24 15:44:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 48067 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 2E73E385803B for ; Wed, 24 Nov 2021 15:44:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E73E385803B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1637768688; bh=lZu4YXVtiNQhYNuekzNRJRqrwtW5EPOQ87cbRGsKEUk=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=sYrMfWUFrD7hLXfmwftllSRFvS+rShWCtFFyLUEMSKWi5kx52fmC0NZEUmZOjiCqx rWzZQlI1WP/qnp9/HvCFpMGCWFPVP812oQeySKvreIrVHd2QY4dXsrpEfI4bTtHGaP LO0p3o6RZSFDrv8cw12I+ev+v/duzD0JyFwoK1T8= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by sourceware.org (Postfix) with ESMTPS id B94473857C5B for ; Wed, 24 Nov 2021 15:44:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B94473857C5B Received: by mail-wm1-x34a.google.com with SMTP id n16-20020a05600c3b9000b003331973fdbbso1692368wms.0 for ; Wed, 24 Nov 2021 07:44:28 -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:message-id:mime-version:subject:from:to:cc; bh=lZu4YXVtiNQhYNuekzNRJRqrwtW5EPOQ87cbRGsKEUk=; b=eMM1l+AvMngj0xYC0XhsiTYm2XVh1V3IN48JgSKVGY8ZYhGcfcC91sdrNBjtaB52ze zxHIz5BH6j4ttk9Y1hrE7k/70mQ3rKfpRvBQ1SvpXJtezv646NEoteIZxS6R5BdJDak3 ocI90PCFRO1EeLRz2fY/YL3D1jz/FFLvvrFHg+nUUG1cyHS0iys/iscoHIam2F0WdPux XGF61+Lkt/+2qCiaV7QH/BK0pGWUhcaeKMV5ouwll1JiCLaDBD9VmWWGqFa1ZFr9gErl JRT7fxHgFCjpGJZcmX4e2d/SRcnIYpkUHLHsN8nnu7JbFwsXIIjWzU+i1RuQUGLZfDLk 1Mlw== X-Gm-Message-State: AOAM5317eOZhwF26zy34LL/mGnBzRDbSoLvC5yfcKG1QLLJ0eue9RBK7 LxIauE+xxkNuIjaE6SQeaIpS+CkQ993KC9ByQDFQ/BM7kghMrqAYjqIbpczas48Bv1uUkeCuL7P QmD8KimnUlb2b1y4vbxX5fef9qR1PstGYNLvSQAQ3IfbUyIN3RU0C0XS9GiaKhZ0tMGz6JXU= X-Google-Smtp-Source: ABdhPJzxF7pDWkgHelM1J+/cD0XGkAK7Rj1MyKMTN88MDhSxdSSWpo9xUl4gIwDVBNRKPnUNHyDBUrBcw8h2Tg== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:4c51:3b6d:f043:b3c2]) (user=maennich job=sendgmr) by 2002:a05:600c:19d1:: with SMTP id u17mr16546080wmq.148.1637768667561; Wed, 24 Nov 2021 07:44:27 -0800 (PST) Date: Wed, 24 Nov 2021 15:44:12 +0000 Message-Id: <20211124154411.2434715-1-maennich@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH] XML writer: adjust tracking of emitted declarations To: libabigail@sourceware.org X-Spam-Status: No, score=-22.8 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: Matthias Maennich via Libabigail From: =?utf-8?q?Matthias_M=C3=A4nnich?= Reply-To: Matthias Maennich Cc: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Replace the std::unordered_map used to track emitted declarations with a std::unordered_set as the map only ever held "true". The container itself does not need to be marked mutable because record_decl_as_emitted is called in a non-const context and can itself be made non-const. In addition, the method decl_is_emitted calls a helper which no longer used anywhere else and can be inlined. The remaining two methods are always called on non-type declarations, so the test that existed in decl_is_emitted can be dropped. * abg-writer.cc (write_context): Replace mutable m_emitted_decls_map with plain m_emitted_decls_set. (decl_name_is_emitted): Inlined into decl_is_emitted; dropped. (decl_is_emitted): Drop is_type check and inline decl_name_is_emitted. Look up in set instead of map. (record_decl_as_emitted): Make non-const. Insert into set instead of map. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich Signed-off-by: Dodji Seketeli --- src/abg-writer.cc | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index 693f99c6528d..f7efd671a485 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -168,9 +168,7 @@ class write_context class_tmpl_shared_ptr_map m_class_tmpl_id_map; string_elf_symbol_sptr_map_type m_fun_symbol_map; string_elf_symbol_sptr_map_type m_var_symbol_map; - mutable unordered_map m_emitted_decls_map; + unordered_set m_emitted_decls_set; write_context(); @@ -747,17 +745,6 @@ public: type_is_emitted(const type_base_sptr& t) const {return type_is_emitted(t.get());} - /// Test if the name of a given decl has been written out to the XML - /// output. - /// - /// @param the decl to consider. - /// - /// @return true if the decl has already been emitted, false - /// otherwise. - bool - decl_name_is_emitted(const interned_string& name) const - {return m_emitted_decls_map.find(name) != m_emitted_decls_map.end();} - /// Test if a given decl has been written out to the XML output. /// /// @param the decl to consider. @@ -767,13 +754,9 @@ public: bool decl_is_emitted(decl_base_sptr& decl) const { - if (is_type(decl)) - return false; - string repr = get_pretty_representation(decl, true); interned_string irepr = decl->get_environment()->intern(repr); - bool is_emitted = decl_name_is_emitted(irepr); - return is_emitted; + return m_emitted_decls_set.find(irepr) != m_emitted_decls_set.end(); } /// Record a declaration-only class as being emitted. @@ -829,11 +812,11 @@ public: /// /// @param decl the decl to consider. void - record_decl_as_emitted(const decl_base_sptr &decl)const + record_decl_as_emitted(const decl_base_sptr& decl) { string repr = get_pretty_representation(decl, true); interned_string irepr = decl->get_environment()->intern(repr); - m_emitted_decls_map[irepr] = true; + m_emitted_decls_set.insert(irepr); } /// Get the set of types that have been emitted.