On Wed, Aug 26, 2015 at 07:49:36PM +0200, Tito wrote:
> 
> 
> On 08/26/2015 07:18 PM, Isaac Dunham wrote:
> >By my test (Debian Jessie, GCC 4.9.2, glibc shared build), the results are:
> >function                                             old     new   delta
> >is_suffixed_with                                      61      45     -16
> >------------------------------------------------------------------------------
> >(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-16)             Total: -16 
> >bytes
> >    text        data     bss     dec     hex filename
> >  760460        2092    9080  771632   bc630 busybox_old
> >  760444        2092    9080  771616   bc620 busybox_unstripped
> >---
> >  libbb/compare_string_array.c | 15 +++++----------
> >  1 file changed, 5 insertions(+), 10 deletions(-)
> >
> >diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c
> >index 3dbd3eb..2a46e62 100644
> >--- a/libbb/compare_string_array.c
> >+++ b/libbb/compare_string_array.c
> >@@ -35,17 +35,12 @@ char* FAST_FUNC is_prefixed_with(const char *string, 
> >const char *key)
> >   */
> >  char* FAST_FUNC is_suffixed_with(const char *string, const char *key)
> >  {
> >-    size_t key_len = strlen(key);
> >-    ssize_t len_diff = strlen(string) - key_len;
> >+    char *ret;
> >
> >-    if (len_diff >= 0) {
> >-            string += len_diff;
> >-            if (strcmp(string, key) == 0) {
> >-                    return (char*)string;
> >-            }
> >-    }
> >-
> >-    return NULL;
> >+    ret = strstr(string, key);
> >+    if (ret && strcmp(ret, key))
> >+            ret = NULL;
> >+    return ret;
> >  }
> >
> >  /* returns the array index of the string */
> >
> 
> Hi,
> I think this will not work in case of:
> 
> haystack = provatesttest  needle = test
> 
> I suspect it will return NULL instead of last "test"

Yup, you're right.
It won't pay off if you do a loop, so ignore this.

Thanks,
Isaac
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to