Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

strcasestr optimize for speed and size

revisit this and shave a bit more off on code size

Change-Id: I90546b931780c6779960129619a41cc6592c44e1

authored by

William Wilgus and committed by
William Wilgus
27aff7ec 6f542b65

+23 -25
+23 -25
firmware/common/strcasestr.c
··· 36 36 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 37 37 char* strcasestr (const char* haystack, const char* needle) 38 38 { 39 - chartype needle_ch = tolower(*needle++); 40 - chartype needle_upch = toupper(needle_ch); 41 - chartype ch_h; 42 - char* match = (char*)haystack; /* if needle empty return haystack */ 39 + const char* match, *needle_search; 40 + chartype needle_ch, needle_upch, ch_h; 43 41 44 - if (needle_ch != 0) { 42 + if (*needle == 0) /* if needle empty return haystack */ 43 + return (char*)haystack; 44 + 45 + while(1) 46 + { 47 + needle_search = needle; 48 + needle_ch = tolower(*needle_search++); 49 + needle_upch = toupper(needle_ch); 45 50 /* find the first matching character */ 46 - do { 51 + do 52 + { 47 53 ch_h = *haystack++; 48 54 if (ch_h == 0) /* end of haystack no match.. */ 49 55 return NULL; 50 56 } while (ch_h != needle_ch && ch_h != needle_upch); 57 + match = haystack; 58 + goto case_match; 51 59 52 - match = (char*) haystack - 1; 53 60 /* find the first non-matching character */ 54 - lcase_match: 55 - while (ch_h == needle_ch) { 56 - ch_h = *haystack++; 57 - needle_ch = tolower(*needle++); 61 + while (ch_h == needle_ch) 62 + { 63 + case_match: 64 + ch_h = *match++; 65 + needle_ch = tolower(*needle_search++); 58 66 if (needle_ch == 0) /* end of needle, found match.. */ 59 - return match; 67 + return (char*)haystack - 1; 60 68 } 61 - /* lcase or ucase match */ 62 69 needle_upch = toupper(needle_ch); 63 - while (ch_h == needle_upch || ch_h == needle_ch) { 64 - ch_h = *haystack++; 65 - needle_ch = tolower(*needle++); 66 - if (needle_ch == 0) /* end of needle, found match.. */ 67 - return match; 68 - 69 - if (ch_h == needle_ch) 70 - goto lcase_match; 71 - needle_upch = toupper(needle_ch); 72 - } 73 - match = NULL; 70 + if (ch_h == needle_upch) 71 + goto case_match; 72 + haystack = match; 74 73 } 75 - return match; 76 74 } 77 75 #else 78 76 char* strcasestr (const char* phaystack, const char* pneedle)