From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id A17C03858C2C; Sun, 14 Nov 2021 23:25:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A17C03858C2C Received: by mail-wr1-x42e.google.com with SMTP id c4so26923449wrd.9; Sun, 14 Nov 2021 15:25:45 -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=7qDeGvmRON35qRwN2Y6sfwA8R9JraG0Rwxa/TVVW6e4=; b=nCttzlEYPT6QfhrMX2pSpm9PsYWPcNMIUrF3uhC+exerxUXUMqOy0ZLZHwYj63t9KF oEBg2Z/2adjf5hQeAWCRfQOutg4AY6xOfPbFvRpHN4d31ZszCpnn76CVnfBOpIrUIJ0C OxUqxnyXQdfZOSoiJuAUk1Kv1h+WAGixEj3d1YnLTj7VNsIY1nLeiVBDg4FiaVP9UFO4 RXC1F+vC9Y8ezO5POrQLSQTfVV4ponYsK1PpO7WIxA3dCSDVVwj7xbg0qhqA4IcvJzHg vFoxcegxZk0sC82LNqnD10xmJnhdDJMpFXUTQVy1Bk59vV/ikPEiGRKKfRLvnEz4LR6A 8y2g== X-Gm-Message-State: AOAM531jaTreQ8I4DFueg+lUyhe1KEmTLkGYO9dI6MBKRfCKiuk0WhpF fRl6EJpEAZoeHQRT2zi9y0XCJoUMLuNt6gSq0eE= X-Google-Smtp-Source: ABdhPJwbNRDCET9PGd3P4BhcbMUyS+6KLN4MdQ/k2cZQuftuxml8bZC9mfdPxV3WyGIeqUhpGKKzlK9ftbZzPN5u110= X-Received: by 2002:a05:6000:18a3:: with SMTP id b3mr42027116wri.343.1636932344347; Sun, 14 Nov 2021 15:25:44 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Sun, 14 Nov 2021 23:25:32 +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=-0.9 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: Sun, 14 Nov 2021 23:25:46 -0000 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.