From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 48657 invoked by alias); 17 Mar 2018 20:11:03 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 48646 invoked by uid 89); 17 Mar 2018 20:11:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 17 Mar 2018 20:11:01 +0000 Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id CC0AF1E4B2; Sat, 17 Mar 2018 16:10:59 -0400 (EDT) Subject: Re: [RFC PATCH v5 1/9] Convert substitute_path_component to C++ From: Simon Marchi To: Philipp Rudo , gdb-patches@sourceware.org Cc: Omair Javaid , Yao Qi , arnez@linux.vnet.ibm.com References: <20180312153115.47321-1-prudo@linux.vnet.ibm.com> <20180312153115.47321-2-prudo@linux.vnet.ibm.com> <0e10fbb0-3138-301d-2e6b-747121544c71@simark.ca> Message-ID: Date: Sat, 17 Mar 2018 20:11:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <0e10fbb0-3138-301d-2e6b-747121544c71@simark.ca> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2018-03/txt/msg00341.txt.bz2 On 2018-03-15 10:15 PM, Simon Marchi wrote: >> diff --git a/gdb/auto-load.c b/gdb/auto-load.c >> index 70bddbc862..a7f9635252 100644 >> --- a/gdb/auto-load.c >> +++ b/gdb/auto-load.c >> @@ -175,21 +175,18 @@ std::vector> auto_load_safe_path_vec; >> substitute_path_component. */ >> >> static std::vector> >> -auto_load_expand_dir_vars (const char *string) >> +auto_load_expand_dir_vars (const std::string &string) > > All the usages of auto_load_expand_dir_vars pass in a char pointer. This means that > a temporary std::string is created for the duration of the call (one copy) and another > one is done lower. I would suggest either to leave the parameter as const char * to > avoid that copy. I stumbled on the discussion you had with Pedro on the v1 patchset: https://sourceware.org/ml/gdb-patches/2017-01/msg00210.html so I thought it would be good to expand a little bit. A quote from that thread: > Thus you should only use one kind of string through out GDB, either char * or > std::string. And as GDB decided to move to C++ for me std::string is the way you > should go. I don't think we should be so dogmatic. There are times where a "const char *" is appropriate, others where std::string is appropriate. A const std::string& is not appropriate for a function that is potentially called with string literals, since it will always require a copy. As mentioned in that thread, backporting std::string_view would be the way to go. But until then, I think we should keep using const char * in those cases. Simon