From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta036.useast.a.cloudfilter.net (omta036.useast.a.cloudfilter.net [44.202.169.35]) by sourceware.org (Postfix) with ESMTPS id 273B13858C66 for ; Mon, 16 Oct 2023 23:05:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 273B13858C66 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 273B13858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697497532; cv=none; b=UTBzrDX0kbrxsTEKgNvcN7I67Qjf7fpAdk+z/P6ysx3wdh0fgfHTandssK6PlIzAAsHYwJyjVPHamrP2C2yJmhZt6Wv8dgX0wkVHtt/mhGvnoc62phXHn+oClKiX0tXwMejSbQuYOVd8hHxpFudCP6hkRer2dmYyyKuyLkmK+0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697497532; c=relaxed/simple; bh=4dzzNtxBMTqzTBObyfUG1B9YFRpG/XVqmRsCgqsaAes=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tXUGwb52CYLzTTv3nl+TUdUr8ONEc//cbpkgEl+Fatg/HyDhDkBnC+kNCTmVVWkMkCAd+FtHyAQB+CGN1KkTZwJDQQoFaJ3eyAgpv28uFFOQa1686BNLoWKeuBB4npCzM4WLM7oe5fY9FX4mp71hcsUX4di9uPlL1aS3P77xlxU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6006a.ext.cloudfilter.net ([10.0.30.182]) by cmsmtp with ESMTPS id sWRIqaCYpOFScsWeQqX1Lc; Mon, 16 Oct 2023 23:05:30 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id sWePqPEk8fDvnsWePqbRYu; Mon, 16 Oct 2023 23:05:29 +0000 X-Authority-Analysis: v=2.4 cv=O7oqATxW c=1 sm=1 tr=0 ts=652dc1b9 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=bhdUkHdE2iEA:10 a=Qbun_eYptAEA:10 a=L9FUc2kav00zxSIjVgoA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=0C6l7nz7piUjFkIo+b4nNbSuqHP2WAmIH87wtOrKDJo=; b=vyuJkX76jojdSoz8K7oIPJjQd3 PsGWbkNyYiSMafT7Gq2NRVp8uZiBeUGVVnhKbcSbwhcs6ScpFjNWUBmIvptuuvO4Ae7XLmiL0QhC/ +Pw6Zk+ISwqbEF0PiJtcfh+dz; Received: from [161.98.8.3] (port=38490 helo=prentzel.ci.boulder.co.us) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.1) (envelope-from ) id 1qsWeP-003Maa-0p; Mon, 16 Oct 2023 17:05:29 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 4/7] Use try_emplace in index-write.c Date: Mon, 16 Oct 2023 17:02:43 -0600 Message-ID: <20231016230527.1820819-5-tom@tromey.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231016230527.1820819-1-tom@tromey.com> References: <20231016230527.1820819-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 161.98.8.3 X-Source-L: No X-Exim-ID: 1qsWeP-003Maa-0p X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (prentzel.ci.boulder.co.us) [161.98.8.3]:38490 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfEg+JfWfmf21/8b2QxRojlTQgHHduWbh6VbK5gHD3zm6VFVq0Gp2CiIqiO//Qe0Lqi2PYoXv4S1md4Q4IdfqhlF3sEtOPNWhlYTtC+jKJrp5iiDjrq1B aKf8L7Z6m7lJwPT9LbpjPoxsGgpb8pNv1ILi5KZq8zY1qwZf9JJ38ajzWTFQ8m1jTPJU/4eBCuL7JfozpUpiYdBwu735vHHb7pE= X-Spam-Status: No, score=-3024.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: index-write.c has a comment indicating that C++17's try_emplace could be used. This patch makes the change. --- gdb/dwarf2/index-write.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index a6d770c9ee5..e402d407ee7 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -384,24 +384,16 @@ write_hash_table (mapped_symtab *symtab, data_buf &output, data_buf &cpool) continue; gdb_assert (entry.index_offset == 0); - /* Finding before inserting is faster than always trying to - insert, because inserting always allocates a node, does the - lookup, and then destroys the new node if another node - already had the same key. C++17 try_emplace will avoid - this. */ - const auto found - = symbol_hash_table.find (entry.cu_indices); - if (found != symbol_hash_table.end ()) + const auto &pair = symbol_hash_table.try_emplace (entry.cu_indices, + cpool.size ()); + entry.index_offset = pair.first->second; + if (pair.second) { - entry.index_offset = found->second; - continue; + /* Newly inserted. */ + cpool.append_offset (entry.cu_indices.size ()); + for (const auto index : entry.cu_indices) + cpool.append_offset (index); } - - symbol_hash_table.emplace (entry.cu_indices, cpool.size ()); - entry.index_offset = cpool.size (); - cpool.append_offset (entry.cu_indices.size ()); - for (const auto index : entry.cu_indices) - cpool.append_offset (index); } } -- 2.41.0