From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9190 invoked by alias); 2 Apr 2018 02:15:34 -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 9004 invoked by uid 89); 2 Apr 2018 02:15:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=opinion 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; Mon, 02 Apr 2018 02:15:31 +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 D05271E4B2; Sun, 1 Apr 2018 22:15:23 -0400 (EDT) Subject: Re: [RFA 04/10] Return std::string from canonical_to_fullform To: Tom Tromey , gdb-patches@sourceware.org References: <20180401163539.15314-1-tom@tromey.com> <20180401163539.15314-5-tom@tromey.com> From: Simon Marchi Message-ID: Date: Mon, 02 Apr 2018 02:15:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180401163539.15314-5-tom@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2018-04/txt/msg00032.txt.bz2 On 2018-04-01 12:35 PM, Tom Tromey wrote: > @@ -1458,34 +1453,39 @@ convert_results_to_lsals (struct linespec_state *self, > > struct decode_line_2_item > { > - /* The form using symtab_to_fullname. > - It must be xfree'ed after use. */ > - char *fullform; > + decode_line_2_item (std::string &&fullform_, std::string &&displayform_, > + bool selected_) > + : fullform (std::move (fullform_)), > + displayform (std::move (displayform_)), > + selected (selected_) > + { > + } > + > + /* The form using symtab_to_fullname. */ > + std::string fullform; > > - /* The form using symtab_to_filename_for_display. > - It must be xfree'ed after use. */ > - char *displayform; > + /* The form using symtab_to_filename_for_display. */ > + std::string displayform; > > /* Field is initialized to zero and it is set to one if the user > requested breakpoint for this entry. */ > unsigned int selected : 1; > }; > > -/* Helper for qsort to sort decode_line_2_item entries by DISPLAYFORM and > - secondarily by FULLFORM. */ > +/* Helper for std::sort to sort decode_line_2_item entries by > + DISPLAYFORM and secondarily by FULLFORM. */ > > -static int > -decode_line_2_compare_items (const void *ap, const void *bp) > +static bool > +decode_line_2_compare_items (const decode_line_2_item &a, > + const decode_line_2_item &b) > { > - const struct decode_line_2_item *a = (const struct decode_line_2_item *) ap; > - const struct decode_line_2_item *b = (const struct decode_line_2_item *) bp; > int retval; > > - retval = strcmp (a->displayform, b->displayform); > - if (retval != 0) > - return retval; > - > - return strcmp (a->fullform, b->fullform); > + if (a.displayform < b.displayform) > + return true; > + if (a.displayform == b.displayform) > + return a.fullform < b.fullform; > + return false; It's probably a matter of opinion, but I think this would read better like this: if (a.displayform != b.displayform) return a.displayform < b.displayform; return a.fullform < b.fullform; In any case, the retval variable can be removed. Otherwise, LGTM. Simon