Minor simplification of (Python) find_thread_object

Message ID 20170122045025.4413-1-simon.marchi@polymtl.ca
State New, archived
Headers

Commit Message

Simon Marchi Jan. 22, 2017, 4:50 a.m. UTC
  Since the reference to the Inferior Python object is managed by
gdbpy_ref (RAII), we can return directly from the loop.  It's just a
leftover from the cleanups era.

gdb/ChangeLog:

	* python/py-inferior.c (find_thread_object): Return directly
	from the loop.  Remove "found" variable.
---
 gdb/python/py-inferior.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
  

Comments

Simon Marchi Jan. 23, 2017, 4:26 p.m. UTC | #1
On 2017-01-21 23:50, Simon Marchi wrote:
> Since the reference to the Inferior Python object is managed by
> gdbpy_ref (RAII), we can return directly from the loop.  It's just a
> leftover from the cleanups era.
> 
> gdb/ChangeLog:
> 
> 	* python/py-inferior.c (find_thread_object): Return directly
> 	from the loop.  Remove "found" variable.
> ---
>  gdb/python/py-inferior.c | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
> index 9e10d62c51..f3ae82ed54 100644
> --- a/gdb/python/py-inferior.c
> +++ b/gdb/python/py-inferior.c
> @@ -264,13 +264,7 @@ find_thread_object (ptid_t ptid)
>    for (thread = ((inferior_object *)(inf_obj.get ()))->threads; 
> thread;
>         thread = thread->next)
>      if (ptid_equal (thread->thread_obj->thread->ptid, ptid))
> -      {
> -	found = thread->thread_obj;
> -	break;
> -      }
> -
> -  if (found)
> -    return found;
> +      return thread->thread_obj;
> 
>    return NULL;
>  }

Self-review: I have just noticed that the "found" variable declaration 
can be removed.
  
Pedro Alves Jan. 23, 2017, 5:32 p.m. UTC | #2
On 01/23/2017 04:26 PM, Simon Marchi wrote:

> Self-review: I have just noticed that the "found" variable declaration
> can be removed.

OK with that change.

Thanks,
Pedro Alves
  
Simon Marchi Jan. 23, 2017, 8:32 p.m. UTC | #3
On 2017-01-23 12:32, Pedro Alves wrote:
> On 01/23/2017 04:26 PM, Simon Marchi wrote:
> 
>> Self-review: I have just noticed that the "found" variable declaration
>> can be removed.
> 
> OK with that change.
> 
> Thanks,
> Pedro Alves

Thanks, pushed.
  

Patch

diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 9e10d62c51..f3ae82ed54 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -264,13 +264,7 @@  find_thread_object (ptid_t ptid)
   for (thread = ((inferior_object *)(inf_obj.get ()))->threads; thread;
        thread = thread->next)
     if (ptid_equal (thread->thread_obj->thread->ptid, ptid))
-      {
-	found = thread->thread_obj;
-	break;
-      }
-
-  if (found)
-    return found;
+      return thread->thread_obj;
 
   return NULL;
 }