[PATCH libICE 2/2] make IceProtocolShutdown() more readable

Eric Engestrom eric.engestrom at imgtec.com
Tue Sep 12 09:27:17 UTC 2017


On Friday, 2017-09-08 20:03:03 +0200, walter harms wrote:
> I found IceProtocolShutdown() hard to read only to find that was
> it does it aktually very simple. So i rearranged the code to make
> it more readable.
> 
> Signed-off-by: Walter Harms <wharms at bfs.de>
> ---
>  src/shutdown.c | 47 ++++++++++++++++++++---------------------------
>  1 file changed, 20 insertions(+), 27 deletions(-)
> 
> diff --git a/src/shutdown.c b/src/shutdown.c
> index 90e9ded..98376a7 100644
> --- a/src/shutdown.c
> +++ b/src/shutdown.c
> @@ -40,45 +40,38 @@ IceProtocolShutdown (
>  	int	majorOpcode
>  )
>  {
> +    int i;
> +
>      if (iceConn->proto_ref_count == 0 || iceConn->process_msg_info == NULL ||
>          majorOpcode < 1 || majorOpcode > _IceLastMajorOpcode)
>      {
>  	return (0);
>      }
> -    else
> -    {
> -	/*
> -	 * Make sure this majorOpcode is really being used.
> -	 */
> -
> -	int i;
> +
> +
> +    /*
> +     * Make sure this majorOpcode is really being used.
> +     */
> 
> -	for (i = iceConn->his_min_opcode; i <= iceConn->his_max_opcode; i++)
> -	{
> -	    if (iceConn->process_msg_info[
> -		i - iceConn->his_min_opcode].in_use &&
> -                iceConn->process_msg_info[
> -		i - iceConn->his_min_opcode].my_opcode == majorOpcode)
> -		break;
> -	}
> +    for (i = iceConn->his_min_opcode; i <= iceConn->his_max_opcode; i++)
> +      {
> +	int n=i - iceConn->his_min_opcode;

spaces around `=`, and can you be more consistent with the indentation?
(mostly avoid mixing tabs and spaces).

With that fixed:
Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com>

> +	if (iceConn->process_msg_info[n].in_use &&
> +	    iceConn->process_msg_info[n].my_opcode == majorOpcode)
> +	  {
> 
> -	if (i > iceConn->his_max_opcode)
> -	{
> -	    return (0);
> -	}
> -	else
> -	{
>  	    /*
>  	     * OK, we can shut down the protocol.
>  	     */
> 
> -	    iceConn->process_msg_info[
> -		i - iceConn->his_min_opcode].in_use = False;
> -	    iceConn->proto_ref_count--;
> +	      iceConn->process_msg_info[n].in_use = False;
> +	      iceConn->proto_ref_count--;
> +	      return (1);
> +	  }
> +				
> +      }
> 
> -	    return (1);
> -	}
> -    }
> +    return (0);
>  }
> 
> 
> -- 
> 2.1.4
> 


More information about the xorg-devel mailing list