Re: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-04 Thread Kang-Che Sung
On Saturday, July 4, 2020, Harald van Dijk wrote: > > This is really the same problem as with standard library functions such as strchr(). The function should have a return type of char* if its argument has type char*. The function should have a return type of const char* if its argument has type

Re: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-04 Thread Harald van Dijk
On 04/07/2020 09:56, Emmanuel Deloget wrote: On Fri, Jul 3, 2020 at 9:15 PM Tito wrote: On 7/3/20 6:13 PM, Xabier Oneca -- xOneca wrote: Also, there's a warning compiling this function: return discards ‘const’ qualifier from pointer target type Hi, cast it? char* FAST_FUNC

Re: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-04 Thread Emmanuel Deloget
Hello, On Fri, Jul 3, 2020 at 9:15 PM Tito wrote: > > > > On 7/3/20 6:13 PM, Xabier Oneca -- xOneca wrote: > > Hi all, > > > >>> On Fri, 2020-07-03 at 08:12 +0200, Tito wrote: > >>> [...] > Improved version: > > char* last_char_is(const char *s, int c) { > if (!s ||

Re: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-03 Thread Tito
On 7/3/20 6:13 PM, Xabier Oneca -- xOneca wrote: > Hi all, > >>> On Fri, 2020-07-03 at 08:12 +0200, Tito wrote: >>> [...] Improved version: char* last_char_is(const char *s, int c) { if (!s || !*s) return NULL; while (*(s + 1))s++; return (c == *s)

Re: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-03 Thread Xabier Oneca -- xOneca
Hi all, > >On Fri, 2020-07-03 at 08:12 +0200, Tito wrote: > >[...] > >> Improved version: > >> > >> char* last_char_is(const char *s, int c) { > >> if (!s || !*s) return NULL; > >> while (*(s + 1))s++; > >> return (c == *s) ? (char *)s : NULL; > >> } Let me "improve" the Tito's

Re: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-03 Thread Jody Bruchon
This is what I love about coding. We'll play with optimizing some of the simplest and least important things on a whim. May the winds of hackerdom ever be in your favor. On July 3, 2020 3:34:23 AM EDT, Bernd Petrovitsch wrote: >On Fri, 2020-07-03 at 08:12 +0200, Tito wrote: >[...] >> Improved

Re: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-03 Thread Bernd Petrovitsch
On Fri, 2020-07-03 at 08:12 +0200, Tito wrote: [...] > Improved version: > > char* last_char_is(const char *s, int c) { > if (!s || !*s) return NULL; > while (*(s + 1))s++; > return (c == *s) ? (char *)s : NULL; > } I like that;-) > or if you like gotos: > > char* FAST_FUNC

Re: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-03 Thread Tito
On 7/3/20 4:58 AM, Jody Bruchon wrote: > > > On July 2, 2020 3:26:29 PM EDT, Tito wrote: >> hi, >> just for fun I add my version: >> >> char* FAST_FUNC last_char_is(const char *s, int c) { >> while (s && *s && *(s + 1)) s++; >> return (c == *s) ? (char *)s : NULL; >> } > > That's

Re: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-02 Thread Jody Bruchon
On July 2, 2020 3:26:29 PM EDT, Tito wrote: >hi, >just for fun I add my version: > >char* FAST_FUNC last_char_is(const char *s, int c) { > while (s && *s && *(s + 1)) s++; > return (c == *s) ? (char *)s : NULL; >} That's pretty small, but it performs three comparisons for each

Re: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-02 Thread Tito
On 7/2/20 12:02 AM, Jody Bruchon wrote: > From 10389ff81b4ee5a7db293cf5d6205d8944e51901 Mon Sep 17 00:00:00 2001 > From: Jody Bruchon > Date: Wed, 1 Jul 2020 17:55:04 -0400 > Subject: [PATCH] libbb/last_char_is: rewrite for smaller and faster code > > Signed-off-by: Jody Bruch

Re: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-02 Thread Kang-Che Sung
On Friday, July 3, 2020, Jody Bruchon wrote: > > > On July 2, 2020 11:29:06 AM EDT, Kang-Che Sung wrote: >>On Thursday, July 2, 2020, Jody Bruchon wrote: >>> /* Find out if the last character of a string matches the one given >>*/ >>> -char* FAST_FUNC last_char_is(const char *s, int c) >>>

Re: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-02 Thread Kang-Che Sung
On Thursday, July 2, 2020, Jody Bruchon wrote: > /* Find out if the last character of a string matches the one given */ > -char* FAST_FUNC last_char_is(const char *s, int c) > +char* FAST_FUNC last_char_is(char *s, char c) Why are you removing the const qualifier, and how would that reduce the

[PATCH] libbb/last_char_is: rewrite for smaller and faster code

2020-07-01 Thread Jody Bruchon
From 10389ff81b4ee5a7db293cf5d6205d8944e51901 Mon Sep 17 00:00:00 2001 From: Jody Bruchon Date: Wed, 1 Jul 2020 17:55:04 -0400 Subject: [PATCH] libbb/last_char_is: rewrite for smaller and faster code Signed-off-by: Jody Bruchon ---  libbb/last_char_is.c | 14 +-  1 file changed, 5