On July 2, 2020 3:26:29 PM EDT, Tito <farmat...@tiscali.it> 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 character until the end and effectively scans the string twice in "parallel." If a bad pointer is passed in s, it'll segfault at the equality check in the return statement even though the first comparison is supposed to be a null pointer safeguard. _______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
- [PATCH 4/4] last_char_is: code shrink Martin Lewis
- Re: [PATCH 4/4] last_char_is: code shrink Denys Vlasenko
- Re: [PATCH 4/4] last_char_is: code shrink Martin Lewis
- Re: [PATCH 4/4] last_char_is: code shr... Jody Bruchon
- Re: [PATCH 4/4] last_char_is: code... Martin Lewis
- Re: [PATCH 4/4] last_char_is:... Jody Bruchon
- [PATCH] libbb/last_char_is: r... Jody Bruchon
- Re: [PATCH] libbb/last_ch... Kang-Che Sung
- Re: [PATCH] libbb/last_ch... Kang-Che Sung
- Re: [PATCH] libbb/last_ch... Tito
- Re: [PATCH] libbb/last_ch... Jody Bruchon
- Re: [PATCH] libbb/last_ch... Tito
- Re: [PATCH] libbb/last_ch... Bernd Petrovitsch
- Re: [PATCH] libbb/last_ch... Jody Bruchon
- Re: [PATCH] libbb/last_ch... Xabier Oneca -- xOneca
- Re: [PATCH] libbb/last_ch... Tito
- Re: [PATCH] libbb/last_ch... Emmanuel Deloget
- Re: [PATCH] libbb/last_ch... Harald van Dijk
- Re: [PATCH] libbb/last_ch... Kang-Che Sung
- [PATCH 2/4] compare_string_array: code shrink Martin Lewis
- Re: [PATCH 2/4] compare_string_array: code shr... Denys Vlasenko