[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] vi: fix regex search compilation error
From:       Ron Yorston <rmy () pobox ! com>
Date:       2021-07-14 8:03:25
Message-ID: 60ee9a4d.yDlLsGVvpBElaBEs%rmy () pobox ! com
[Download RAW message or body]

Bernhard Reutner-Fischer wrote:
>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 suspect the inelegance is inherent.  Here's the current code:

    1    while (*s) {
    2       if (*s == c)
    3          return (char *)s;
    4       if (*s == '\\')
    5          if (*++s == '\0')
    6             break;
    7       s++;
    8    }

It has the advantage that all the special magic is in lines 4-6.
If you ignore them it's just a standard strchr().

    1    while (*s) {
    2       if (*s == c)
    3          return (char *)s;
    4       if (*s++ == '\\')
    5          if (*s++ == '\0')
    6             break;
    7    }

This is more uniform but adds 6 bytes of bloat.

    1    while (*s) {
    2       if (*s == c)
    3          return (char *)s;
    4       if (*s++ == '\\')
    5          if (*s != '\0')
    6             s++;
    7    }

This makes it clearer that we only skip the character following the
backslash if it's not NUL and it avoids the break.  5 bytes of bloat.

Dietmar's suggestion is indeed equivalent and adds no bloat.  But,
in my opinion, needs more effort to understand.

If the current code is unclear maybe it needs a comment:

      // skip char after backslash, unless it's NUL

Ron
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic