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

List:       busybox
Subject:    AW: [PATCH] nc_bloaty: Code shrink in findline, use memchr instead.
From:       Walter Harms <wharms () bfs ! de>
Date:       2020-02-04 10:04:12
Message-ID: 7231452918804f8687a0115ab46046fa () bfs ! de
[Download RAW message or body]


________________________________________
Von: busybox <busybox-bounces@busybox.net> im Auftrag von Martin Lewis <martin.lewis.x84@gmail.com>
Gesendet: Dienstag, 4. Februar 2020 00:52
An: busybox@busybox.net
Betreff: [PATCH] nc_bloaty: Code shrink in findline, use memchr instead.

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
---
 networking/nc_bloaty.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c
index 034e03d21..190a8bcb1 100644
--- a/networking/nc_bloaty.c
+++ b/networking/nc_bloaty.c
@@ -237,24 +237,11 @@ static void arm(unsigned secs)
  Not distinguishing \n vs \r\n for the nonce; it just works as is... */
 static unsigned findline(char *buf, unsigned siz)

a bit of nit picking:
unsigned siz -> unsigned int size
of perhaps size_t size? (need by memchr() ).


re,
 wh

 {
-       char * p;
-       int x;
-       if (!buf)                        /* various sanity checks... */
-               return 0;
-       if (siz > BIGSIZ)
+       char *p;
+       if (!buf || siz > BIGSIZ)
                return 0;
-       x = siz;
-       for (p = buf; x > 0; x--) {
-               if (*p == '\n') {
-                       x = (int) (p - buf);
-                       x++;                        /* 'sokay if it points just past the end! */
-Debug("findline returning %d", x);
-                       return x;
-               }
-               p++;
-       } /* for */
-Debug("findline returning whole thing: %d", siz);
-       return siz;
+       p = memchr(buf, '\n', siz);
+       return p ? (p - buf + 1) : siz;
 } /* findline */

 /* doexec:
--
2.11.0

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
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