Speeding up the finding of the longest filename in the current folder.
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5356 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
677e9474f7
commit
8a058d1f9a
|
@ -1,6 +1,9 @@
|
||||||
2015-08-13 Benno Schulenberg <bensberg@justemail.net>
|
2015-08-13 Benno Schulenberg <bensberg@justemail.net>
|
||||||
* src/search.c (do_find_bracket): Remove mistaken comparison between
|
* src/search.c (do_find_bracket): Remove mistaken comparison between
|
||||||
pointer and literal character. Found with cppcheck.
|
pointer and literal character. Found with cppcheck.
|
||||||
|
* src/browser.c (browser_init): Speed up the finding of the longest
|
||||||
|
filename: don't limit the value to that of COLS all the time, as this
|
||||||
|
is done later anyway, and don't bother skipping the dot entry.
|
||||||
|
|
||||||
2015-08-12 Benno Schulenberg <bensberg@justemail.net>
|
2015-08-12 Benno Schulenberg <bensberg@justemail.net>
|
||||||
* src/chars.c: UTF-8 is a stateless encoding, so there is no need to
|
* src/chars.c: UTF-8 is a stateless encoding, so there is no need to
|
||||||
|
|
|
@ -436,29 +436,30 @@ void browser_init(const char *path, DIR *dir)
|
||||||
|
|
||||||
assert(path != NULL && path[strlen(path) - 1] == '/' && dir != NULL);
|
assert(path != NULL && path[strlen(path) - 1] == '/' && dir != NULL);
|
||||||
|
|
||||||
/* Set longest to zero, just before we initialize it. */
|
|
||||||
longest = 0;
|
longest = 0;
|
||||||
|
|
||||||
|
/* Find the length of the longest filename in the current folder. */
|
||||||
while ((nextdir = readdir(dir)) != NULL) {
|
while ((nextdir = readdir(dir)) != NULL) {
|
||||||
size_t d_len;
|
size_t name_len = strlenpt(nextdir->d_name);
|
||||||
|
|
||||||
/* Don't show the "." entry. */
|
if (name_len > longest)
|
||||||
if (strcmp(nextdir->d_name, ".") == 0)
|
longest = name_len;
|
||||||
continue;
|
|
||||||
|
|
||||||
d_len = strlenpt(nextdir->d_name);
|
|
||||||
if (d_len > longest)
|
|
||||||
longest = (d_len > COLS) ? COLS : d_len;
|
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
rewinddir(dir);
|
/* Put 10 characters' worth of blank space between columns of filenames
|
||||||
|
|
||||||
/* Put 10 columns' worth of blank space between columns of filenames
|
|
||||||
* in the list whenever possible, as Pico does. */
|
* in the list whenever possible, as Pico does. */
|
||||||
longest += 10;
|
longest += 10;
|
||||||
|
|
||||||
|
/* Make sure longest is between 15 and COLS. */
|
||||||
|
if (longest < 15)
|
||||||
|
longest = 15;
|
||||||
|
if (longest > COLS)
|
||||||
|
longest = COLS;
|
||||||
|
|
||||||
|
rewinddir(dir);
|
||||||
|
|
||||||
if (filelist != NULL)
|
if (filelist != NULL)
|
||||||
free_chararray(filelist, filelist_len);
|
free_chararray(filelist, filelist_len);
|
||||||
|
|
||||||
|
@ -486,12 +487,6 @@ void browser_init(const char *path, DIR *dir)
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
/* Make sure longest is between 15 and COLS. */
|
|
||||||
if (longest < 15)
|
|
||||||
longest = 15;
|
|
||||||
if (longest > COLS)
|
|
||||||
longest = COLS;
|
|
||||||
|
|
||||||
/* Set width to zero, just before we initialize it. */
|
/* Set width to zero, just before we initialize it. */
|
||||||
width = 0;
|
width = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue