From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id lDotOu0Gk2WBTjAAWB0awg (envelope-from ) for ; Mon, 01 Jan 2024 13:39:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1704134381; bh=a+oIY4P8WDSFjTTiThhT3/PSLTUva4NjZLn95nHT75M=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=hzpw8IzYPWZ/iGoFLeF/bwY5nlwPleIEens3uaQIvqkq+PaOqovFaaC4d8WCJii8G GIarbV6HhCVInSv5IUie/p8Xan1+oIj0ZX9juex9QRTFnFu++VKFyaW+MqNqSjPVvZ rEri6po3oKxLcaV1qnRiUcFQJevAE9htysOtdUTw= Received: by simark.ca (Postfix, from userid 112) id DDA011E0D0; Mon, 1 Jan 2024 13:39:41 -0500 (EST) Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=d2WhJ1Ks; dkim-atps=neutral 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 C11171E0BB for ; Mon, 1 Jan 2024 13:39:39 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 65CB53858401 for ; Mon, 1 Jan 2024 18:39:39 +0000 (GMT) Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 3EAD33858D1E for ; Mon, 1 Jan 2024 18:39:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3EAD33858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3EAD33858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704134362; cv=none; b=j6dwUVJs4M/3IrzHyocPZD59CqBqd1DGDtdDGscG5BzL3X9ck+hp4z1Od9HkblZK105HUNx7fn7t9WFPyiH7Vhuxb/xbDPRLfMtvn+nYLmXmLl/LEGO6EEDWdpL4Jtd4SCTBFzoJ8alEgVpMzlbv9R0/3EvtOzuO9BHiT/9m8Xg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704134362; c=relaxed/simple; bh=a+oIY4P8WDSFjTTiThhT3/PSLTUva4NjZLn95nHT75M=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Lx99NT+81izhgtrnEIsL/vGmkx1MaOgvFVOz+3s5Vm/TUEBTTeKnQu3MFia004cS4g0oSvjdAIeDCHvyQRPDblAKJexvfb2O58qDSmYHQkCaSfu29ZaPPkLzySqnmXjWq/tnYIWdJ+MfantEjVML7xHV/8kQfvuL7tIYJAEjbNg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1704134360; bh=a+oIY4P8WDSFjTTiThhT3/PSLTUva4NjZLn95nHT75M=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=d2WhJ1KsIPBC2LexJcPup/3rrcyMeXVW5mB4m0xD/Tc3Xf41r0/crj5Kn0govnzwQ u3pHG2QIFBN5QnMuny5f0Ln+lAtzCwM6q6RJ9/SWndWyCSBksGUAHoCys3jw0WshSA kL52pypMS5tRNXS6erLCdeUYhR/ysnb2BQqfszsI= Received: from [10.0.0.11] (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 2091D1E0B9; Mon, 1 Jan 2024 13:39:19 -0500 (EST) Message-ID: <41eff013-1d3c-4345-b8a1-9e4ed41ec05a@simark.ca> Date: Mon, 1 Jan 2024 13:39:19 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/6] Use vector in remote-fileio.c Content-Language: en-US To: Lancelot SIX , Tom Tromey Cc: gdb-patches@sourceware.org References: <20231231-remote-fileio-v1-0-249cc6c440d9@tromey.com> <20231231-remote-fileio-v1-2-249cc6c440d9@tromey.com> <20240101142041.dndg63bv42hs7lpo@octopus> From: Simon Marchi In-Reply-To: <20240101142041.dndg63bv42hs7lpo@octopus> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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 On 2024-01-01 09:20, Lancelot SIX wrote: > Hi Tom, > > I have a couple of comments below. > > On Sun, Dec 31, 2023 at 01:25:39PM -0700, Tom Tromey wrote: >> This changes remote_fio_data to be an object holding a vector. This >> simplifies the code somewhat. >> --- >> gdb/remote-fileio.c | 51 +++++++++++++++++---------------------------------- >> 1 file changed, 17 insertions(+), 34 deletions(-) >> >> diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c >> index 367edb54f74..4891b0c5b92 100644 >> --- a/gdb/remote-fileio.c >> +++ b/gdb/remote-fileio.c >> @@ -37,9 +37,9 @@ >> #endif >> #include >> >> -static struct { >> - int *fd_map; >> - int fd_map_size; >> +static struct >> +{ >> + std::vector fd_map; >> } remote_fio_data; >> >> #define FIO_FD_INVALID -1 >> @@ -51,16 +51,13 @@ static int remote_fio_system_call_allowed = 0; >> static int >> remote_fileio_init_fd_map (void) >> { >> - int i; >> - >> - if (!remote_fio_data.fd_map) >> + if (remote_fio_data.fd_map.empty ()) >> { >> - remote_fio_data.fd_map = XNEWVEC (int, 10); >> - remote_fio_data.fd_map_size = 10; >> + remote_fio_data.fd_map.resize (10); >> remote_fio_data.fd_map[0] = FIO_FD_CONSOLE_IN; >> remote_fio_data.fd_map[1] = FIO_FD_CONSOLE_OUT; >> remote_fio_data.fd_map[2] = FIO_FD_CONSOLE_OUT; >> - for (i = 3; i < 10; ++i) >> + for (int i = 3; i < 10; ++i) >> remote_fio_data.fd_map[i] = FIO_FD_INVALID; > > std::vector::resize has an overload which takes a value to use > for new elements of the vector. This could be simplified as > > remote_fio_data.fd_map.resize (10, FIO_FD_INVALID); > remote_fio_data.fd_map[0] = FIO_FD_CONSOLE_IN; > remote_fio_data.fd_map[1] = FIO_FD_CONSOLE_OUT; > remote_fio_data.fd_map[2] = FIO_FD_CONSOLE_OUT; > > See below, but overall, I don’t really think we need to keep the "grow > by 10" strategy when using std::vector, this could simply be > > remote_fio_data.fd_map.emplace_back (FIO_FD_CONSOLE_IN) > remote_fio_data.fd_map.emplace_back (FIO_FD_CONSOLE_OUT) > remote_fio_data.fd_map.emplace_back (FIO_FD_CONSOLE_OUT) I agree with Lancelot. And from what I saw after quickly skimming the code, remote_fileio_resize_fd_map and remote_fileio_next_free_fd could be removed, since they callers can use simple vector operations. Simon