This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] Remove a VEC from type.c


On 2018-05-29 11:10 AM, Tom Tromey wrote:
> This removes a VEC from type.c, by using std::vector.
> 
> While doing this I also took the opportunity to change
> types_deeply_equal to return bool.  This caught some weird code in
> typy_richcompare, now fixed.
> 
> And, since I was changing types_deeply_equal, it seemed like a good
> idea to also change types_equal, so this patch includes that as well.
> 
> Tested by the buildbot.

LGTM, I just noted some nits.

> diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
> index 4f77a5214e3..2be0d2e97d9 100644
> --- a/gdb/gdbtypes.c
> +++ b/gdb/gdbtypes.c
> @@ -3551,10 +3551,10 @@ integer_types_same_name_p (const char *first, const char *second)
>    return 1;
>  }
>  
> -/* Compares type A to type B returns 1 if the represent the same type
> -   0 otherwise.  */
> +/* Compares type A to type B returns true if the represent the same
> +   type, false otherwise.  */

Could you fix the "the" -> "they" typo at the same time?  It wouldn't hurt to
improve the syntax as well, it reads a bit weird.

> -/* A helper function to compare two strings.  Returns 1 if they are
> -   the same, 0 otherwise.  Handles NULLs properly.  */
> +/* A helper function to compare two strings.  Returns true if they are
> +   the same, false otherwise.  Handles NULLs properly.  */
>  
> -static int
> +static bool
>  compare_maybe_null_strings (const char *s, const char *t)
>  {
>    if (s == NULL && t != NULL)
> -    return 0;
> +    return false;
>    else if (s != NULL && t == NULL)
> -    return 0;
> +    return false;
>    else if (s == NULL && t== NULL)
> -    return 1;
> +    return true;
>    return strcmp (s, t) == 0;
>  }

Not really related to your patch, but I think we could reduce the number of
required comparisons/arithmetic operations by doing

if (s == NULL || t == NULL)
  return s == t;

return strcmp (s, t) == 0;

Simon


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]