[PATCH] shrink last_char_is function even more

Denys Vlasenko vda.linux at googlemail.com
Sun Jul 19 18:48:29 UTC 2020


On Thu, Jul 16, 2020 at 7:53 AM Stefan Seyfried
<stefan.seyfried at googlemail.com> wrote:
>
> Am 09.07.20 um 21:13 schrieb Tito:
> > On 7/9/20 9:56 PM, Martin Lewis wrote:
> >> Please note that my original patch is still smaller:
> >> http://lists.busybox.net/pipermail/busybox/2020-June/088026.html
> >
> > Hi,
> > yes I know. This is smaller than what is in git now.
> > I understood that Denis rejected your patch:
> > "This scans the string twice, unnecessarily. Let's not do that."
>
> I'd really like an explanation, because for me this sentence looks
> wrong, I cannot see two scans, only one strrchr(). Or is strrchr so wrong?

strrchr(s,c) will first find the end of s, then go backwards looking for c.
The second part is wasted work, we only need to check the *last* char == c.


More information about the busybox mailing list