From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id lZWpMy/b2GdFZhMAWB0awg (envelope-from ) for ; Mon, 17 Mar 2025 22:32:15 -0400 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=TjRkeffO; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C88461E100; Mon, 17 Mar 2025 22:32:15 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 6A90C1E05C for ; Mon, 17 Mar 2025 22:32:15 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 23C7C385841E for ; Tue, 18 Mar 2025 02:32:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 23C7C385841E Authentication-Results: sourceware.org; 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=TjRkeffO Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id 27BBC3858D3C for ; Tue, 18 Mar 2025 02:15:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 27BBC3858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 27BBC3858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1742264108; cv=none; b=gXHqiO9rNKJNXEsbDoWGiv26vxLvXVxBYydppKLEjkvEzswPPI9qkcyPAW5K77bRgkuHZTgv1Srpj43J73MTORikFl95SgxT1KPZ5sTgpWDxGyzL69qt2pSH33Nzadr3Vv5+UC39Hf/e18AhDV0sWP6ao1JryHBBifkrjRuIH60= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1742264108; c=relaxed/simple; bh=7k8KOaDhZepFqXvq/rIpEHAARTwQsLGtKPEZnshSnWc=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=bwKOt3c7Mhsxfb0pU3EGvDTZI0T2mUlsRLpnw107D8/14d4VPu26ZTwzxttjLSlnHWiFuT7GSo0aW1wjkQiKJ5nMax8kfVPctOkP+GnsT+yz8jer4AWKduuw3YPRYfEAVpjkaGXYQUuw6uR0iPGiUvj2aqVcxXQymqfO45kEmdQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27BBC3858D3C Received: from eig-obgw-5001a.ext.cloudfilter.net ([10.0.29.139]) by cmsmtp with ESMTPS id u98WtES7Lf1UXuMTzt4Ap8; Tue, 18 Mar 2025 02:15:07 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id uMTyt8IrHRxIGuMTytQRAY; Tue, 18 Mar 2025 02:15:07 +0000 X-Authority-Analysis: v=2.4 cv=N/viFH9B c=1 sm=1 tr=0 ts=67d8d72b a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=Vs1iUdzkB0EA:10 a=ItBw4LHWJt0A:10 a=8kpLEgudV8QKMxLrZmoA:9 a=QEXdDO2ut3YA:10 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=qwErJW0Myfv+yw7tV1E73ycqVj0YxSeNrxu7ndoNxhM=; b=TjRkeffOh/6Ll+7kRAeRWZ5z3w JhwzoEPNAbtOdAv5mKtjLPohjbN1H++7/EK44y8hfHvmvC0EVaYIcCheOgCy6Nu7JTeriWMPdysh0 xVFjaV+vbwZqVdup/hfBaRkH4; Received: from 97-122-96-32.hlrn.qwest.net ([97.122.96.32]:36240 helo=prentzel.local) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.1) (envelope-from ) id 1tuMTx-00000002cIx-3J8X; Mon, 17 Mar 2025 20:15:05 -0600 From: Tom Tromey Date: Mon, 17 Mar 2025 20:15:11 -0600 Subject: [PATCH 18/19] Use gdb unordered map in tui-io.c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250317-replace-std-stuff-v1-18-7ba4ee88e218@tromey.com> References: <20250317-replace-std-stuff-v1-0-7ba4ee88e218@tromey.com> In-Reply-To: <20250317-replace-std-stuff-v1-0-7ba4ee88e218@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.2 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: 97.122.96.32 X-Source-L: No X-Exim-ID: 1tuMTx-00000002cIx-3J8X X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-96-32.hlrn.qwest.net (prentzel.local) [97.122.96.32]:36240 X-Source-Auth: tom+tromey.com X-Email-Count: 19 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfOI5ufc/UY2CQOP/1SvUaFsqoKqSljcOSSPgDiyIp3/F0VweaJ5X6CoXhz917MRDM1Ttr9vhCqtR0Vy0aOeTt2GwWMlx6DY41hO4OTtOCnqSXpQ4s1HP y4lZtnrTdiqcuWM6gpGfPJwwJ0Szpc9tCbxa0EoSbcP1mBSjKyvaX3JQvg+1st8f8RTlNlUTeI4WzE674CcbN4Ydc/3nsHWO24M= 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 This changes tui.c to use gdb::unordered_map. ui_file_style::color is changed a little as well; operator< is no longer needed, but a simple hash function is added. --- gdb/tui/tui-io.c | 37 ++++++++++++++++++++++++++++++++----- gdb/ui-style.h | 18 ++++-------------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 7013a543ab61f268e06e78ccad52aa5cc8419700..5d012b2e2077c8c8bd710f5694b0fcd7061b23ea 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -42,7 +42,7 @@ #include "gdbsupport/filestuff.h" #include "completer.h" #include "gdb_curses.h" -#include +#include "gdbsupport/unordered_map.h" #include "pager.h" #include "gdbsupport/gdb-checked-static-cast.h" @@ -178,9 +178,25 @@ tui_putc (char c) update_cmdwin_start_line (); } +/* Specialization of std::hash for colors. */ + +namespace std +{ +template<> struct hash +{ + typedef ui_file_style::color argument_type; + typedef std::size_t result_type; + + result_type operator() (const argument_type &color) const noexcept + { + return color.hash (); + } +}; +} + /* This maps colors to their corresponding color index. */ -static std::map color_map; +static gdb::unordered_map color_map; /* This holds a pair of colors and is used to track the mapping between a color pair index and the actual colors. */ @@ -190,16 +206,27 @@ struct color_pair int fg; int bg; - bool operator< (const color_pair &o) const + bool operator== (const color_pair &other) const noexcept + { + return fg == other.fg && bg == other.bg; + } +}; + +struct color_pair_hash +{ + using is_avalanching = void; + + size_t operator() (const color_pair &val) const noexcept { - return fg < o.fg || (fg == o.fg && bg < o.bg); + static_assert (std::has_unique_object_representations_v); + return ankerl::unordered_dense::detail::wyhash::hash (&val, sizeof (val)); } }; /* This maps pairs of colors to their corresponding color pair index. */ -static std::map color_pair_map; +static gdb::unordered_map color_pair_map; /* This is indexed by ANSI color offset from the base color, and holds the corresponding curses color constant. */ diff --git a/gdb/ui-style.h b/gdb/ui-style.h index d814588254143149e5b24a45f3a3cdd8a24c91da..4e994966e27c582335952f58c33887fc7c0b0b86 100644 --- a/gdb/ui-style.h +++ b/gdb/ui-style.h @@ -151,22 +151,12 @@ struct ui_file_style return ! (*this == other); } - bool operator< (const color &other) const + /* Compute a simple hash code for this object. */ + size_t hash () const { - if (m_color_space != other.m_color_space) - return m_color_space < other.m_color_space; if (is_simple ()) - return m_value < other.m_value; - if (m_red < other.m_red) - return true; - if (m_red == other.m_red) - { - if (m_green < other.m_green) - return true; - if (m_green == other.m_green) - return m_blue < other.m_blue; - } - return false; + return m_value; + return (m_red << 16) + (m_green << 8) + m_red; } color_space colorspace () const -- 2.46.1