> -----Original Message-----
> From: busybox <[email protected]> On Behalf Of Bernhard 
> Reutner-Fischer
> Sent: Wednesday, July 14, 2021 12:51 AM
>
> On Tue, 13 Jul 2021 21:42:05 +0100
> Ron Yorston <[email protected]> wrote:
>
> > Bernhard Reutner-Fischer wrote:
> > >If i'm not mistaken, the s++ is fully redundant here although it seems
> > >that my gcc-11 does not optimize it like if we manually spell it out
> > >like in the attached?
> >
> > I don't think it's possible to avoid two increments.  When a backslash
> > is detected we want to move past it and the following character.
> >
> > Consider:
> >
> >    strchr_backslash("\\/abc/def", '/');
> >
> > The original code and Denys' rewrite return a pointer to "/def"; your
> > suggestion returns a pointer to "/abc/def".
>
> @@ -2686,10 +2686,9 @@ static char *strchr_backslash(const char *s, int
> c) while (*s) {
>  if (*s == c)
>  return (char *)s;
> -if (*s == '\\') # 1
> -if (*++s == '\0') # 2
> +if (*s++ == '\\') # 3
> +if (*s == '\0') # 4
>  break;
> -s++; # 5
>  }
>  return NULL;
>
> How come? Obviously i'm slow today and in addition blind.
> So..
> 1) if *s == backslash
> increment s
> old: if the incremented s points to 0 (when we break, #2)
> new: always (#3)
> 2) If *s was a backslash
> old: if the incremented *s was 0 (#2)
> new: if the previously incremented *s was 0 (#3)
> then break and return NULL
>
> ah oh in the old code we double increment (only) if the first was a
> backslash _not_ followed by a nul.
> hmz. So is there a more elegant way to express that which i don't see
> right now?

I can't say whether that's more elegant, only that it's equivalent:

while (*s)
{
if (*s == c)
return (char *)s;
if (*s != '\\' || *++s)
s++;
}
 return NULL;
--
Best regards,
Dietmar Schindler
________________________________
manroland Goss web systems GmbH | Managing Director: Franz Kriechbaum
Registered Office: Augsburg | Trade Register: AG Augsburg | HRB-No.: 32609 | 
VAT: DE815764857

Confidentiality note:
This message and any attached documents may contain confidential or proprietary 
information of manroland|Goss. These materials are intended only for the use of 
the intended recipient. If you are not the intended recipient of this 
transmission, you are hereby notified that any distribution, disclosure, 
printing, copying, storage, modification or the taking of any action in 
reliance upon this transmission is strictly prohibited. Delivery of this 
message to any person other than the intended recipient shall not compromise or 
waive such confidentiality, privilege or exemption from disclosure as to this 
communication. If you have received this communication in error, please 
immediately notify the sender and delete the message from your system. All 
liability for viruses is excluded to the fullest extent permitted by law.
________________________________
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to