[PATCH] libbb/last_char_is: rewrite for smaller and faster code
Bernd Petrovitsch
bernd at petrovitsch.priv.at
Fri Jul 3 07:34:23 UTC 2020
On Fri, 2020-07-03 at 08:12 +0200, Tito wrote:
[...]
> Improved version:
>
> char* last_char_is(const char *s, int c) {
> if (!s || !*s) return NULL;
> while (*(s + 1))s++;
> return (c == *s) ? (char *)s : NULL;
> }
I like that;-)
> or if you like gotos:
>
> char* FAST_FUNC last_char_is(const char *s, int c)
> {
> if (!s || !*s) goto OUT;
> while (*(s + 1))s++;
> if (c == *s) return (char *) s;
> OUT:
> return NULL;
> }
>
> bloatcheck is same for both:
Both produce probably the sam asm output anyways ...
> function old new delta
> last_char_is 53 42 -11
> ------------------------------------------------------------------------------
> (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-11) Total: -11 bytes
> text data bss dec hex filename
> 980860 16891 1872 999623 f40c7 busybox_old
> 980849 16891 1872 999612 f40bc busybox_unstripped
MfG,
Bernd
--
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
There is no cloud, just other people computers. - FSFE
LUGA : http://www.luga.at
More information about the busybox
mailing list