From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gIOFHDMGlWL3SQkAWB0awg (envelope-from ) for ; Mon, 30 May 2022 14:00:19 -0400 Received: by simark.ca (Postfix, from userid 112) id 708881E222; Mon, 30 May 2022 14:00:19 -0400 (EDT) Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=yNN+JIA7; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id B29A91E143 for ; Mon, 30 May 2022 14:00:18 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 60FA6384B0CC for ; Mon, 30 May 2022 18:00:18 +0000 (GMT) Received: from alt-proxy28.mail.unifiedlayer.com (alt-proxy28.mail.unifiedlayer.com [74.220.216.123]) by sourceware.org (Postfix) with ESMTPS id 23B123853804 for ; Mon, 30 May 2022 17:59:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 23B123853804 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id 9250210040515 for ; Mon, 30 May 2022 17:59:38 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id vjg2nujZtwPf0vjg2nUgvP; Mon, 30 May 2022 17:59:38 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=F5ySyotN c=1 sm=1 tr=0 ts=6295060a a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=oZkIemNP1mAA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=XiPlK4sjKDSmHtNkUf8A: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=L2UkQTkRIvAzDBLDIfw43NFjr7tVRkzgYi0kQ9gf9gM=; b=yNN+JIA74aVHacQfIVcJ9B4c3K 0+EV1VIbocPy0QiuoeTyQPZ7sp/BJm6kIX+eq/CHAmd+vEU4Y0Ij+NaY5erbXeUF8IiFgi8LI9L9t BoBwh8KB+BXeBaJx8uduoDMMZ; Received: from 71-211-158-194.hlrn.qwest.net ([71.211.158.194]:45630 helo=prentzel.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nvjg2-002OyG-22; Mon, 30 May 2022 11:59:38 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 5/6] Change registry to use less memory Date: Mon, 30 May 2022 11:59:33 -0600 Message-Id: <20220530175934.3872892-6-tom@tromey.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220530175934.3872892-1-tom@tromey.com> References: <20220530175934.3872892-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: 71.211.158.194 X-Source-L: No X-Exim-ID: 1nvjg2-002OyG-22 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-158-194.hlrn.qwest.net (prentzel.Home) [71.211.158.194]:45630 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" The registry code creates "registry_data" objects that hold the free function and the index; then the registry keys refer to this object. However, only the index is really useful, and now that registries have a private implementation, just the index can be stored and we can reduce the memory use of registries a little bit. This also simplifies the code somewhat. --- gdb/registry.h | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/gdb/registry.h b/gdb/registry.h index 27592ff6e2a..f2d952ac847 100644 --- a/gdb/registry.h +++ b/gdb/registry.h @@ -159,7 +159,7 @@ class registry } /* The underlying key. */ - const typename registry::registry_data *m_key; + const unsigned m_key; }; /* Clear all the data associated with this container. This is @@ -167,13 +167,16 @@ class registry void clear_registry () { /* Call all the free functions. */ - for (const auto &datum : get_registrations ()) + std::vector ®istrations + = get_registrations (); + unsigned last = registrations.size (); + for (unsigned i = 0; i < last; ++i) { - void *elt = m_fields[datum->index]; + void *elt = m_fields[i]; if (elt != nullptr) { - datum->free (elt); - m_fields[datum->index] = nullptr; + registrations[i] (elt); + m_fields[i] = nullptr; } } } @@ -183,50 +186,40 @@ class registry /* Registry callbacks have this type. */ typedef void (*registry_data_callback) (void *); - /* The type of a key. */ - struct registry_data - { - unsigned index; - registry_data_callback free; - }; - /* Get a new key for this particular registry. FREE is a callback. When the container object is destroyed, all FREE functions are called. The data associated with the container object is passed to the callback. */ - static const registry_data *new_key (registry_data_callback free) + static unsigned new_key (registry_data_callback free) { - std::unique_ptr result (new registry_data); - std::vector> ®istrations + std::vector ®istrations = get_registrations (); - result->index = registrations.size (); - result->free = free; - registrations.emplace_back (std::move (result)); - return registrations.back ().get (); + unsigned result = registrations.size (); + registrations.push_back (free); + return result; } /* Set the datum associated with KEY in this container. */ - void set (const registry_data *key, void *datum) + void set (unsigned key, void *datum) { - m_fields[key->index] = datum; + m_fields[key] = datum; } /* Fetch the datum associated with KEY in this container. If 'set' has not been called for this key, nullptr is returned. */ - void *get (const registry_data *key) + void *get (unsigned key) { - return m_fields[key->index]; + return m_fields[key]; } /* The data stored in this instance. */ std::vector m_fields; /* Return a reference to the vector of all the registrations that - have been made. We do separate allocations here so that the - addresses are stable and can be used as keys. */ - static std::vector> &get_registrations () + have been made. */ + static std::vector &get_registrations () { - static std::vector> registrations; + static std::vector registrations; return registrations; } }; -- 2.34.1