[1/2] ptid_{lwp,tid}_p: Remove unnecessary checks

Message ID 20170404183235.10589-1-simon.marchi@ericsson.com
State New, archived
Headers

Commit Message

Simon Marchi April 4, 2017, 6:32 p.m. UTC
  The calls to ptid_equal in ptid_lwp_p and ptid_tid_p that compare the
argument to minus_one_ptid and null_ptid are not necessary.  The calls
in question are:

   if (ptid_equal (minus_one_ptid, ptid)
       || ptid_equal (null_ptid, ptid))
     return 0;

minus_one_ptid is { .pid = -1, .lwp = 0, .tid = 0 }
null_ptid is { .pid = 0, .lwp = 0, .tid = 0 }

If the ptid argument is either of them, the statements

  return (ptid_get_lwp (ptid) != 0);

and

  return (ptid_get_tid (ptid) != 0);

will yield the same result (0/false).

gdb/ChangeLog:

	* common/ptid.c (ptid_lwp_p, ptid_tid_p): Remove comparison with
	minus_one_ptid and null_ptid.
---
 gdb/common/ptid.c | 8 --------
 1 file changed, 8 deletions(-)
  

Comments

Pedro Alves April 5, 2017, 3:15 p.m. UTC | #1
On 04/04/2017 07:32 PM, Simon Marchi wrote:
> The calls to ptid_equal in ptid_lwp_p and ptid_tid_p that compare the
> argument to minus_one_ptid and null_ptid are not necessary.  The calls
> in question are:
> 
>    if (ptid_equal (minus_one_ptid, ptid)
>        || ptid_equal (null_ptid, ptid))
>      return 0;
> 
> minus_one_ptid is { .pid = -1, .lwp = 0, .tid = 0 }
> null_ptid is { .pid = 0, .lwp = 0, .tid = 0 }
> 
> If the ptid argument is either of them, the statements
> 
>   return (ptid_get_lwp (ptid) != 0);
> 
> and
> 
>   return (ptid_get_tid (ptid) != 0);
> 
> will yield the same result (0/false).
> 
> gdb/ChangeLog:
> 
> 	* common/ptid.c (ptid_lwp_p, ptid_tid_p): Remove comparison with
> 	minus_one_ptid and null_ptid.

Indeed.  LGTM.

Thanks,
Pedro Alves
  
Simon Marchi April 5, 2017, 7:21 p.m. UTC | #2
On 2017-04-05 11:15, Pedro Alves wrote:
> On 04/04/2017 07:32 PM, Simon Marchi wrote:
>> The calls to ptid_equal in ptid_lwp_p and ptid_tid_p that compare the
>> argument to minus_one_ptid and null_ptid are not necessary.  The calls
>> in question are:
>> 
>>    if (ptid_equal (minus_one_ptid, ptid)
>>        || ptid_equal (null_ptid, ptid))
>>      return 0;
>> 
>> minus_one_ptid is { .pid = -1, .lwp = 0, .tid = 0 }
>> null_ptid is { .pid = 0, .lwp = 0, .tid = 0 }
>> 
>> If the ptid argument is either of them, the statements
>> 
>>   return (ptid_get_lwp (ptid) != 0);
>> 
>> and
>> 
>>   return (ptid_get_tid (ptid) != 0);
>> 
>> will yield the same result (0/false).
>> 
>> gdb/ChangeLog:
>> 
>> 	* common/ptid.c (ptid_lwp_p, ptid_tid_p): Remove comparison with
>> 	minus_one_ptid and null_ptid.
> 
> Indeed.  LGTM.
> 
> Thanks,
> Pedro Alves

Thanks, this one is pushed.
  

Patch

diff --git a/gdb/common/ptid.c b/gdb/common/ptid.c
index 05c0db17dd..b56971b9af 100644
--- a/gdb/common/ptid.c
+++ b/gdb/common/ptid.c
@@ -97,10 +97,6 @@  ptid_is_pid (ptid_t ptid)
 int
 ptid_lwp_p (ptid_t ptid)
 {
-  if (ptid_equal (minus_one_ptid, ptid)
-      || ptid_equal (null_ptid, ptid))
-    return 0;
-
   return (ptid_get_lwp (ptid) != 0);
 }
 
@@ -109,10 +105,6 @@  ptid_lwp_p (ptid_t ptid)
 int
 ptid_tid_p (ptid_t ptid)
 {
-  if (ptid_equal (minus_one_ptid, ptid)
-      || ptid_equal (null_ptid, ptid))
-    return 0;
-
   return (ptid_get_tid (ptid) != 0);
 }