nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 0ccdaff9609ea198737b8aed408729d17b61b20c
parent 2d50c4f257e4caf8367916c2390f0bdb80204a8d
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Sat, 16 Apr 2016 11:15:33 +0200

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.

Diffstat:
Msrc/files.c | 19+++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/files.c b/src/files.c @@ -2833,28 +2833,27 @@ char *input_tab(char *buf, bool allow_files, size_t *place, bool char *mzero; const char *lastslash = revstrstr(buf, "/", buf + *place); size_t lastslash_len = (lastslash == NULL) ? 0 : lastslash - buf + 1; - char *match1_mb = charalloc(mb_cur_max() + 1); - char *match2_mb = charalloc(mb_cur_max() + 1); + char *match1_mb = charalloc(mb_cur_max()); + char *match2_mb = charalloc(mb_cur_max()); int match1_mb_len, match2_mb_len; + /* Get the number of characters that all matches have in common. */ 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); + + for (match = 1; match < num_matches; match++) { match2_mb_len = parse_mbchar(matches[match] + common_len, match2_mb, NULL); - match1_mb[match1_mb_len] = '\0'; - match2_mb[match2_mb_len] = '\0'; - if (strcmp(match1_mb, match2_mb) != 0) + if (match1_mb_len != match2_mb_len || + strncmp(match1_mb, match2_mb, match2_mb_len) != 0) break; } if (match < num_matches || matches[0][common_len] == '\0') break; - common_len += parse_mbchar(matches[0] + common_len, NULL, NULL); + common_len += match1_mb_len; } free(match1_mb);