tabbing: avoid recalculating the length of the first match every time
Also don't zero-terminate the matches in order to compare them, but just limit the length of the comparison.master
parent
2d50c4f257
commit
0ccdaff960
17
src/files.c
17
src/files.c
|
@ -2833,28 +2833,27 @@ char *input_tab(char *buf, bool allow_files, size_t *place, bool
|
||||||
char *mzero;
|
char *mzero;
|
||||||
const char *lastslash = revstrstr(buf, "/", buf + *place);
|
const char *lastslash = revstrstr(buf, "/", buf + *place);
|
||||||
size_t lastslash_len = (lastslash == NULL) ? 0 : lastslash - buf + 1;
|
size_t lastslash_len = (lastslash == NULL) ? 0 : lastslash - buf + 1;
|
||||||
char *match1_mb = charalloc(mb_cur_max() + 1);
|
char *match1_mb = charalloc(mb_cur_max());
|
||||||
char *match2_mb = charalloc(mb_cur_max() + 1);
|
char *match2_mb = charalloc(mb_cur_max());
|
||||||
int match1_mb_len, match2_mb_len;
|
int match1_mb_len, match2_mb_len;
|
||||||
|
|
||||||
|
/* Get the number of characters that all matches have in common. */
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
for (match = 1; match < num_matches; match++) {
|
|
||||||
/* Get the number of single-byte characters that all the
|
|
||||||
* matches have in common. */
|
|
||||||
match1_mb_len = parse_mbchar(matches[0] + common_len,
|
match1_mb_len = parse_mbchar(matches[0] + common_len,
|
||||||
match1_mb, NULL);
|
match1_mb, NULL);
|
||||||
|
|
||||||
|
for (match = 1; match < num_matches; match++) {
|
||||||
match2_mb_len = parse_mbchar(matches[match] +
|
match2_mb_len = parse_mbchar(matches[match] +
|
||||||
common_len, match2_mb, NULL);
|
common_len, match2_mb, NULL);
|
||||||
match1_mb[match1_mb_len] = '\0';
|
if (match1_mb_len != match2_mb_len ||
|
||||||
match2_mb[match2_mb_len] = '\0';
|
strncmp(match1_mb, match2_mb, match2_mb_len) != 0)
|
||||||
if (strcmp(match1_mb, match2_mb) != 0)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match < num_matches || matches[0][common_len] == '\0')
|
if (match < num_matches || matches[0][common_len] == '\0')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
common_len += parse_mbchar(matches[0] + common_len, NULL, NULL);
|
common_len += match1_mb_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(match1_mb);
|
free(match1_mb);
|
||||||
|
|
Loading…
Reference in New Issue