[PING^1] newlib: libc: Improved the readability of strspn with minor optimization

Message ID 20240102055615.29320-1-zengxiao@eswincomputing.com
State New
Headers
Series [PING^1] newlib: libc: Improved the readability of strspn with minor optimization |

Commit Message

Xiao Zeng Jan. 2, 2024, 5:56 a.m. UTC
  Signed-off-by: Xiao Zeng <zengxiao@eswincomputing.com>
---
 newlib/libc/string/strspn.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Jeff Johnston Jan. 2, 2024, 7:24 p.m. UTC | #1
Hello,

I modified the code to change the label to "found" instead of "end" since
"end" is usually used to jump to the end of function as opposed to loop.
Modified code has been merged.

-- Jeff J.

On Tue, Jan 2, 2024 at 12:57 AM Xiao Zeng <zengxiao@eswincomputing.com>
wrote:

> Signed-off-by: Xiao Zeng <zengxiao@eswincomputing.com>
> ---
>  newlib/libc/string/strspn.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/newlib/libc/string/strspn.c b/newlib/libc/string/strspn.c
> index baf239947..9d46ce2eb 100644
> --- a/newlib/libc/string/strspn.c
> +++ b/newlib/libc/string/strspn.c
> @@ -41,10 +41,11 @@ strspn (const char *s1,
>        for (c = s2; *c; c++)
>         {
>           if (*s1 == *c)
> -           break;
> +           goto end;
>         }
>        if (*c == '\0')
>         break;
> +end:
>        s1++;
>      }
>
> --
> 2.17.1
>
>
  
Xiao Zeng Jan. 3, 2024, 1:26 a.m. UTC | #2
2024-01-03 03:24  Jeff Johnston <jjohnstn@redhat.com> wrote:
>
 
>Hello,
>
>I modified the code to change the label to "found" instead of "end" since
>"end" is usually used to jump to the end of function as opposed to loop. 
Thank you Jeff, your modifications have made the code more meaningful.

>Modified code has been merged.
>
>-- Jeff J.
>
>On Tue, Jan 2, 2024 at 12:57 AM Xiao Zeng <zengxiao@eswincomputing.com>
>wrote:
>
>> Signed-off-by: Xiao Zeng <zengxiao@eswincomputing.com>
>> ---
>>  newlib/libc/string/strspn.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/newlib/libc/string/strspn.c b/newlib/libc/string/strspn.c
>> index baf239947..9d46ce2eb 100644
>> --- a/newlib/libc/string/strspn.c
>> +++ b/newlib/libc/string/strspn.c
>> @@ -41,10 +41,11 @@ strspn (const char *s1,
>>        for (c = s2; *c; c++)
>>         {
>>           if (*s1 == *c)
>> -           break;
>> +           goto end;
>>         }
>>        if (*c == '\0')
>>         break;
>> +end:
>>        s1++;
>>      }
>>
>> --
>> 2.17.1
>>
>>
 
Thanks
Xiao Zeng
  

Patch

diff --git a/newlib/libc/string/strspn.c b/newlib/libc/string/strspn.c
index baf239947..9d46ce2eb 100644
--- a/newlib/libc/string/strspn.c
+++ b/newlib/libc/string/strspn.c
@@ -41,10 +41,11 @@  strspn (const char *s1,
       for (c = s2; *c; c++)
 	{
 	  if (*s1 == *c)
-	    break;
+	    goto end;
 	}
       if (*c == '\0')
 	break;
+end:
       s1++;
     }