From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [RFA 04/10] Return std::string from canonical_to_fullform
Date: Mon, 02 Apr 2018 02:15:00 -0000 [thread overview]
Message-ID: <e94e9fca-09cf-3c33-2ba2-b4c53dce459e@simark.ca> (raw)
In-Reply-To: <20180401163539.15314-5-tom@tromey.com>
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
next prev parent reply other threads:[~2018-04-02 2:15 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-01 16:35 [RFA 00/10] Remove some cleanups from linespec.c Tom Tromey
2018-04-01 16:35 ` [RFA 03/10] Make copy_token_string return unique_xmalloc_ptr Tom Tromey
2018-04-01 16:35 ` [RFA 07/10] Change streq to return bool Tom Tromey
2018-04-02 2:28 ` Simon Marchi
2018-04-01 16:35 ` [RFA 10/10] Remove unnecessary include from linespec.h Tom Tromey
2018-04-01 16:35 ` [RFA 08/10] More use of std::vector in linespec.c Tom Tromey
2018-04-02 2:35 ` Simon Marchi
2018-04-01 16:35 ` [RFA 04/10] Return std::string from canonical_to_fullform Tom Tromey
2018-04-02 2:15 ` Simon Marchi [this message]
2018-04-01 16:35 ` [RFA 01/10] Remove some cleanups from search_minsyms_for_name Tom Tromey
2018-04-02 1:39 ` Simon Marchi
2018-04-01 16:35 ` [RFA 05/10] Have filter_results take a std::vector Tom Tromey
2018-04-01 16:35 ` [RFA 02/10] Fix some indentation in linespec.c Tom Tromey
2018-04-02 1:49 ` Simon Marchi
2018-04-01 16:35 ` [RFA 06/10] Remove a string copy from event_location_to_sals Tom Tromey
2018-04-01 16:35 ` [RFA 09/10] Remove typep and VEC(typep) from linespec.c Tom Tromey
2018-04-02 2:44 ` [RFA 00/10] Remove some cleanups " Simon Marchi
2018-04-03 22:31 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e94e9fca-09cf-3c33-2ba2-b4c53dce459e@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).