From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 90597 invoked by alias); 12 Jan 2017 13:33:25 -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 90585 invoked by uid 89); 12 Jan 2017 13:33:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=002, slash_string, H*f:sk:f74f518, H*i:sk:f74f518 X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 12 Jan 2017 13:33:23 +0000 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id v0CDTR3j052579 for ; Thu, 12 Jan 2017 08:33:21 -0500 Received: from e06smtp06.uk.ibm.com (e06smtp06.uk.ibm.com [195.75.94.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 27xaca12w7-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 12 Jan 2017 08:33:21 -0500 Received: from localhost by e06smtp06.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 12 Jan 2017 13:33:19 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp06.uk.ibm.com (192.168.101.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 12 Jan 2017 13:33:17 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 808271B08061; Thu, 12 Jan 2017 13:35:58 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v0CDXGRd2883984; Thu, 12 Jan 2017 13:33:16 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E534AA4053; Thu, 12 Jan 2017 12:31:13 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BEA3DA4059; Thu, 12 Jan 2017 12:31:13 +0000 (GMT) Received: from ThinkPad (unknown [9.152.212.192]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 12 Jan 2017 12:31:13 +0000 (GMT) Date: Thu, 12 Jan 2017 13:33:00 -0000 From: Philipp Rudo To: Pedro Alves Cc: gdb-patches@sourceware.org, peter.griffin@linaro.org, yao.qi@arm.com, arnez@linux.vnet.ibm.com Subject: Re: [RFC 2/7] Add libiberty/concat styled concat_path function In-Reply-To: References: <20170112113217.48852-1-prudo@linux.vnet.ibm.com> <20170112113217.48852-3-prudo@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17011213-0024-0000-0000-000002843EA6 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17011213-0025-0000-0000-000021EBFB5C Message-Id: <20170112143315.338f6cfe@ThinkPad> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-01-12_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1701120191 X-IsSubscribed: yes X-SW-Source: 2017-01/txt/msg00224.txt.bz2 Hi Pedro, i see your point. My goal here was to get rid of any C-string. While making this patch i also wanted to use it to get rid of all those concat (path, need_dirsep ? SLASH_STRING : "", NULL) or strcat (path, "/") strcat (path, file) constructs. I gave up when it repeatedly caused memory leaks and use after free errors because of the mixture of C and C++ strings. Fixing them made the code less readable than before. 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. Even when it costs performance. Just my 0.02$ Philipp On Thu, 12 Jan 2017 12:00:22 +0000 Pedro Alves wrote: > On 01/12/2017 11:32 AM, Philipp Rudo wrote: > > static inline int > > -startswith (const char *string, const char *pattern) > > +startswith (std::string str, std::string pattern) > > NAK. > > This is passing by copy, so will force unnecessary deep > string copies all over the place. > > > { > > - return strncmp (string, pattern, strlen (pattern)) == 0; > > + return (str.find (pattern) == 0); > > +} > > + > > I.e., before, this caused 0 copies: > > startswith ("foo, "f"); > > After, you force a deep string copy for "foo", and another > for "f". It's as if you wrote: > > startswith (xstrdup ("foo), xstrdup ("f")); > > > Also, this function is a static inline in a header so that > the compiler can see when "pattern" is a string literal, and > thus strlen can be optimized to a plain 'sizeof (pattern) - 1', > which is very frequent. > > If you want to add overloads that can take "const std::string &" > for convenience, to avoid str.c_str(), that's maybe fine, > but you'd have to add all the combinations of > 'const char *' x 'const std::string &' in the parameters, I > suppose. > > Thanks, > Pedro Alves >