From patchwork Tue Jul 10 08:43:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 941865 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-481272-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="nWchVC1E"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Pwhs5wjbz9s00 for ; Tue, 10 Jul 2018 18:43:41 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=YAGUuSbzEgZbLflPBJQEWG2Nfd0TMwFRVOygzlGTQ1cVKHeRdx Yu9LibSzLpNx+8unO0IYnI4k+NTbZG0NHZD2seOFDzW5zxuTVozFcBDVRoZOShv4 aSmWbgr+4wkGjxyKzDK20/dyso1fa8Th50vyVKAIErQYZxOEAa8TLMzpk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=S2Y7DBdxYqIhzQTVMLMC8AZ+qgo=; b=nWchVC1EdR8iLqkfV4Kb OMwhD/QGjmnm8CDqp5vpN9RjoUy4rRv94MdwCuexrjLKcm6bTsuKUvtvRQGkg+OD R6QY4H1uR7l4PtJN6o5t6jIjzKQscvpTO8O3nyIRHEeYWq/Kv5DdZl+QnoIfqoxz EwWaHrPdfskpgBv9pxNa7ug= Received: (qmail 8982 invoked by alias); 10 Jul 2018 08:43:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 8917 invoked by uid 89); 10 Jul 2018 08:43:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=survive, Hx-languages-length:1407, UD:hash-map.h, hash-map.h X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Jul 2018 08:43:23 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 22ED5AF68; Tue, 10 Jul 2018 08:43:21 +0000 (UTC) Date: Tue, 10 Jul 2018 10:43:20 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: tbsaunde@tbsaunde.org Subject: [PATCH][RFC] Make iterating over hash-map elide copying/destructing Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 The following makes the hash-map iterator dereference return a pair rather than a copy of Value. This matches the hash-table iterator behavior and avoids issues with hash_map > where iterating over the hash-table will call the auto_vec destructor when dereferencing the iterator. I note that the copy ctor of auto_vec should probably be deleted and the hash-table/map iterators should possibly support an alternate "reference" type to the stored Values so we can use vec<> for "references" and auto_vec<> for stored members. But that's out of scope - the patch below seems to survive minimal testing at least. I suppose we still want to somehow hide the copy ctors of auto_vec? How does hash-map growth work here? (I suppose it doesn't...?) Any further comments? Thanks, Richard. 2018-07-10 Richard Biener * hash-map.h (hash_map::iterator::operator*): Return a reference to Value. diff --git a/gcc/hash-map.h b/gcc/hash-map.h index 7861440f3b3..9d2b38a843e 100644 --- a/gcc/hash-map.h +++ b/gcc/hash-map.h @@ -223,10 +223,10 @@ public: return *this; } - std::pair operator* () + std::pair operator* () { hash_entry &e = *m_iter; - return std::pair (e.m_key, e.m_value); + return std::pair (e.m_key, e.m_value); } bool