[PATCH 4/4] last_char_is: code shrink

Martin Lewis martin.lewis.x84 at gmail.com
Thu Jun 11 20:46:00 UTC 2020


function                                             old     new   delta
last_char_is                                          53      30     -23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-23)             Total: -23 bytes
   text	   data	    bss	    dec	    hex	filename
 981322	  16915	   1872	1000109	  f42ad	busybox_old
 981299	  16915	   1872	1000086	  f4296	busybox_unstripped

Signed-off-by: Martin Lewis <martin.lewis.x84 at gmail.com>
---
 libbb/last_char_is.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c
index 66f2e3635..1fff08f9f 100644
--- a/libbb/last_char_is.c
+++ b/libbb/last_char_is.c
@@ -13,11 +13,10 @@
  */
 char* FAST_FUNC last_char_is(const char *s, int c)
 {
-	if (s && *s) {
-		size_t sz = strlen(s) - 1;
-		s += sz;
-		if ( (unsigned char)*s == c)
-			return (char*)s;
+	if (s) {
+		char *index = strrchr(s, c);
+		if (index && *(index + 1) == '\0')
+			return index;
 	}
 	return NULL;
 }
-- 
2.11.0



More information about the busybox mailing list