> +static struct string_list_item *lookup_prefix(struct string_list *map, > + const char *string, size_t len) > +{ > + int i = string_list_find_insert_index(map, string, 1); > + if (i < 0) { > + /* exact match */ > + i = -1 - i; > + /* does it match exactly? */ > + if (!map->items[i].string[len]) > + return &map->items[i]; I'm not sure the condition above is necessary, as I don't see why an exact match would not be an exact match. We have to trust the cmp function (that mailmap sets itself) to not return 0 when the lengths are different. > + } > + > + /* > + * i is at the exact match to an overlong key, or > + * location the possibly overlong key would be inserted, > + * which must be after the real location of the key. > + */ > + while (0 <= --i && i < map->nr) { > + int cmp = strncasecmp(map->items[i].string, string, len); > + if (cmp < 0) > + /* > + * "i" points at a key definitely below the prefix; > + * the map does not have string[0:len] in it. > + */ > + break; > + else if (!cmp && !map->items[i].string[len]) > + /* found it */ > + return &map->items[i]; > + /* > + * otherwise, the string at "i" may be string[0:len] > + * followed by a string that sorts later than string[len:]; > + * keep trying. > + */ > + } > + return NULL; > +} > + I've tried to think about nasty use cases but everything seems fine. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html