← Commit list

bcf91d276

Ron Yorston
Ron Yorston
2021-02-02
SUCCESS Duration: 295s

Subject

libbb: code shrink and speed up index_in_strings()

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

libbb/compare_string_array.c+10 -4
@@ -63,13 +63,19 @@ int FAST_FUNC index_in_str_array(const char *const string_array[], const char *k
int FAST_FUNC index_in_strings(const char *strings, const char *key)
{
- int idx = 0;
+ int j, idx = 0;
while (*strings) {
- if (strcmp(strings, key) == 0) {
- return idx;
+ /* Do we see "key\0" at current position in strings? */
+ for (j = 0; *strings == key[j]; ++j) {
+ if (*strings++ == '\0') {
+ //bb_error_msg("found:'%s' i:%u", key, idx);
+ return idx; /* yes */
+ }
}
- strings += strlen(strings) + 1; /* skip NUL */
+ /* No. Move to the start of the next string. */
+ while (*strings++ != '\0')
+ continue;
idx++;
}
return -1;