This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA 04/10] Return std::string from canonical_to_fullform
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