From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 0CJtCUhMLmV2KDAAWB0awg (envelope-from ) for ; Tue, 17 Oct 2023 04:56:40 -0400 Received: by simark.ca (Postfix, from userid 112) id 1FECA1E0C1; Tue, 17 Oct 2023 04:56:40 -0400 (EDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 12DC11E00F for ; Tue, 17 Oct 2023 04:56:38 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8E624385C301 for ; Tue, 17 Oct 2023 08:56:37 +0000 (GMT) Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by sourceware.org (Postfix) with ESMTPS id 165863858C35 for ; Tue, 17 Oct 2023 08:56:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 165863858C35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 165863858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697532985; cv=none; b=Ak1PEv8MWLvmGG8GQseP8VvtPQV/DNxKqeDDbvah/KAWlJv5/aRqEBqDwa5mOMWLdLDxZpXQxqy2IUHY4sVhHOZtXsu8ym++5BVCHSlqHSpNJqfHNDhllVs/0G/cnSY25vg4T3s959SLV1EGoIjGZ6ZTxgS2PsJfVVlJczOej7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697532985; c=relaxed/simple; bh=nS8YuoxVyYul8XR7MPH7FH8J3LZEeLOeFcILAGKKMdk=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=R23hhAyJdou9vj6b2bs19O8d0g4cQXEoTm5noqg11+btfFbr4x2zb5QHyrYR7FyYkEw559666QVnJMziU/CTA0L9YlKEZtx+CS6CSBpKBofy6lbKCqQfx+ORjYNeJJxFctizOitvnEtH8uMN2jmrRRW4PJaOaYlfOdPAazMxRaY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-40776b20031so30657185e9.0 for ; Tue, 17 Oct 2023 01:56:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697532983; x=1698137783; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pnXwnfmIgFrL4qdMzCnsyGoan26Z4pLsC0seh6Gimvo=; b=j/9vkzKlULjGbu5k4c0W26t7mQSwyQ6iNecwbXG3iE+5rIFnK1GBy76fepMXWWpoBJ oGzjZm38VkktSA83+qWFQhPO/ILtwM2N+3MMsdrnA/J0GKybTKpGsLJ1IA//wesXcca0 bu4nihoN6sggSazAqdzcq/biC3xfVm4OOwXywWACIXAyEmnfAXqm3XPImCcA3bkhGZeN eCbpk+zoGLR3WiNt5VJrzUUMWsbFRz73cWx2M8LOraQfezreCr2pj6Vhr2l2GSW4VGYs dDCbxy8ock7x2bk+Qw3LQiZoddcMDQYkRO80FcJkXuxhFFIo242/wxf6eI0MLP5jv7cf 8HYw== X-Gm-Message-State: AOJu0Yz1qIeeLOzcsFG3Xm/vIdk4uVe51tGTBJ8xubinGAgEimkMCx7P LYVIVjUCg90m71gMSruoPPE= X-Google-Smtp-Source: AGHT+IGKeT4Irayf7y2Oq8P7Q9ifvWTU1AxwhK3W+s4geCO+k6+T3rq3qAdtN4PNCdZWwBgR+bkJbQ== X-Received: by 2002:a05:600c:a48:b0:3fe:2a98:a24c with SMTP id c8-20020a05600c0a4800b003fe2a98a24cmr1175254wmq.26.1697532982702; Tue, 17 Oct 2023 01:56:22 -0700 (PDT) Received: from ?IPV6:2001:8a0:f939:d200:5aaf:ade2:476b:3ff2? ([2001:8a0:f939:d200:5aaf:ade2:476b:3ff2]) by smtp.gmail.com with ESMTPSA id b4-20020a05600c4e0400b004030e8ff964sm9257193wmq.34.2023.10.17.01.56.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Oct 2023 01:56:22 -0700 (PDT) Message-ID: <74ae9885-03ef-45f2-901e-13dd7a69de85@palves.net> Date: Tue, 17 Oct 2023 09:56:20 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 4/7] Use try_emplace in index-write.c Content-Language: en-US To: Tom Tromey , gdb-patches@sourceware.org References: <20231016230527.1820819-1-tom@tromey.com> <20231016230527.1820819-5-tom@tromey.com> From: Pedro Alves In-Reply-To: <20231016230527.1820819-5-tom@tromey.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org On 2023-10-17 00:02, Tom Tromey wrote: > 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 ()); A little odd to take a const ref to the returned pair instead of taking it by value. Better yet, C++17 gives us structured bindings, which lets us hide the ugly pair completely and use helpful names instead of first/second: auto [it, ins] = symbol_hash_table.try_emplace (entry.cu_indices, cpool.size ()); How about we use it here? Pedro Alves > + 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); > } > } >