From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id F00263858403; Mon, 15 Nov 2021 09:11:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F00263858403 Received: by mail-wm1-x32b.google.com with SMTP id p18so3870496wmq.5; Mon, 15 Nov 2021 01:11:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Wf+JW8pUeH7vaW0HqmPwlkUdfWglsORyXxuUiDJHXVs=; b=UbbGhyLcjgayEYZ8mdeKGG1oGquzgU0SAj0ryipUvA1eQ0qKT2i7olYVcqSg7ui+rF cDfVzvNgDwqp+ObN6mhqkxvjnH8z3cbz/LAyfFeJL999xIu9KZt17LWSavITqaUTVoPc fqc0r66OeQBy3PFC5LkYElQw0Y/If/pIkta3QMrBL6hLPTk14jLRUw5GVNFtW5RvnWjV cpAv0/xGElsGlDp5N1l6jRMRPjRl52TJYhpwWw/gI/7cJfCGVetrONWpOSr0qdRvnO9X PY89H9iWfqpwvLPUy3ssX6GFG5ht9nZi29k2+Ryb83VTUYeMSGNB092X+IIhQaJjTfnT 3J5g== X-Gm-Message-State: AOAM531y0sRcb53b03e+bDYnVS9B+VToaAPRO0x/a72US9Qghc7oMPQ3 Queeor6vskeFeCGEbUrwO9k0oSASPFKQ/WcxfBo= X-Google-Smtp-Source: ABdhPJwG9BG/gr4EIfUUMhzseTeTgow/MpH5kOwgjGE6cSoRXLkPStng7FDqcTHkfTXXLj4Ra9peMHM9gK3ur6VnYnw= X-Received: by 2002:a1c:e918:: with SMTP id q24mr1436932wmc.108.1636967466950; Mon, 15 Nov 2021 01:11:06 -0800 (PST) MIME-Version: 1.0 References: <3e66557c-131e-eed0-fc7c-3d1eefd1dcf9@gmail.com> In-Reply-To: <3e66557c-131e-eed0-fc7c-3d1eefd1dcf9@gmail.com> From: Jonathan Wakely Date: Mon, 15 Nov 2021 09:10:55 +0000 Message-ID: Subject: Re: [PATCH] Enhance unordered container merge To: =?UTF-8?Q?Fran=C3=A7ois_Dumont?= Cc: "libstdc++@gcc.gnu.org" , gcc-patches Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Nov 2021 09:11:10 -0000 On Mon, 15 Nov 2021 at 06:00, Fran=C3=A7ois Dumont wrote: > > On 15/11/21 12:25 am, Jonathan Wakely wrote: > > On Sun, 14 Nov 2021 at 13:31, Fran=C3=A7ois Dumont via Libstdc++ > > wrote: > >> libstdc++: Unordered containers merge re-use hash code. > >> > >> When merging between 2 unordered containers with same hasher we = can > >> re-use > >> the cached hash code if any. > > Instead of introducing the _ReuseOrComputeHash type, wouldn't it be > > simpler to just overload _M_hash_code? > > > > > > // Same hash function, use the cached hash code. > > __hash_code > > _M_hash_code(const _Hash&, > > const _Hash_node_value<_Value, true>& __n) const > > { return __n._M_hash_code; } > > > > // Compute hash code using a different hash function, _H2 > > template > > __hash_code > > _M_hash_code(const _H2&, > > const _Hash_node_value<_Value, __cache_hash_code>& __n) const > > { return this->_M_hash_code(_ExtractKey{}(__n._M_v()); } > > > > The first overload is more specialized, so will be chosen when the > > first argument is the same type as _Hash and the cache_has_code > > boolean is true. > > Yes, it is simpler. > > Ok to commit ? Yes, thanks.