From 10389ff81b4ee5a7db293cf5d6205d8944e51901 Mon Sep 17 00:00:00 2001
From: Jody Bruchon <j...@jodybruchon.com>
Date: Wed, 1 Jul 2020 17:55:04 -0400
Subject: [PATCH] libbb/last_char_is: rewrite for smaller and faster code

Signed-off-by: Jody Bruchon <j...@jodybruchon.com>
---
 libbb/last_char_is.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c
index 918526e6c..b146b606f 100644
--- a/libbb/last_char_is.c
+++ b/libbb/last_char_is.c
@@ -9,16 +9,12 @@
 #include "libbb.h"

 /* Find out if the last character of a string matches the one given */
-char* FAST_FUNC last_char_is(const char *s, int c)
+char* FAST_FUNC last_char_is(char *s, char c)
 {
-    if (s) {
-        size_t sz = strlen(s);
-        /* Don't underrun the buffer if the string length is 0 */
-        if (sz != 0) {
-            s += sz - 1;
-            if ((unsigned char)*s == c)
-                return (char*)s;
-        }
+    if (s && *s) {
+        while (*s != '\0') s++;
+        s--;
+        if (*s == c) return s;
     }
     return NULL;
 }
--
2.15.0


_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to