README.md | 6 +++--- nnn.1 | 2 +- nnn.c | 43 +++++++++++++++++++++++-------------------- diff --git a/README.md b/README.md index 22b919df79051fc7eea1294540b42dadfc32874f..5a0ef09fca0b7bb042551229ad108ccdf5873c28 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ ### Introduction nnn is a fork of [noice](http://git.2f30.org/noice/), a blazing-fast lightweight terminal file browser with easy keyboard shortcuts for navigation, opening files and running tasks. noice is developed considering terminal based systems. There is no config file and mime associations are hard-coded. However, the incredible user-friendliness and speed make it a perfect utility on modern distros. -nnn can use the default desktop opener at runtime. It adds new navigation options, enhanced DE integration, a disk usage analyzer mode, comprehensive file details and much more. For a complete list, see [nnn toppings](#nnn-toppings). +nnn can use the default desktop opener at runtime. It adds new navigation options, enhanced DE integration, a disk usage analyzer mode, comprehensive file details and much more. For a complete list, see [nnn toppings](#nnn-toppings). Add to it a huge [performance](#performance) boost. Follow the instructions in the [quickstart](#quickstart) section and see how nnn simplifies those long desktop sessions. @@ -128,7 +128,7 @@ ``` PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 31163 vaio 20 0 65508 53980 2320 S 0.0 1.1 0:01.96 ncdu / -28863 vaio 20 0 24276 11088 2776 S 0.3 0.2 0:02.61 nnn -d +28863 vaio 20 0 21348 7812 2476 S 0.0 0.2 0:01.75 nnn -d ``` nnn vs. mc vs. ranger memory usage while viewing a directory with 10,178 files, sorted by size: @@ -137,7 +137,7 @@ ``` PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 22465 vaio 20 0 233956 192136 7896 S 0.0 3.9 0:05.31 /usr/bin/python -O /usr/bin/ranger 20369 vaio 20 0 64664 10980 6888 S 0.0 0.2 0:00.70 mc -28863 vaio 20 0 20600 7220 2648 S 0.0 0.1 0:00.36 nnn -d +28863 vaio 20 0 19876 6436 2620 S 0.0 0.1 0:00.19 nnn -d ``` ### Installation diff --git a/nnn.1 b/nnn.1 index 2161876ddf9cd86f1b645ac62349e4e9157bfb96..4721ab4d7ae2d1a9b2c15c2e8ca046527c857208 100644 --- a/nnn.1 +++ b/nnn.1 @@ -13,7 +13,7 @@ .Op Ar -h .Op Ar PATH .Sh DESCRIPTION .Nm -(Noice is Not Noice) is a fork of the noice terminal file browser with improved desktop integration, navigation, disk usage analyzer mode, comprehensive file details and much more. It remains a simple and efficient file browser that stays out of your way. +(Noice is Not Noice) is a performance-optimized fork of the noice terminal file browser with improved desktop integration, navigation, disk usage analyzer mode, comprehensive file details and much more. It remains a simple and efficient file browser that stays out of your way. .Pp .Nm defaults to the current directory if diff --git a/nnn.c b/nnn.c index 153f141922de8443771f439d1ec1c1d56bec96bf..a90fab54c7c92e8271d3bdb3ed3f0749a9668da3 100644 --- a/nnn.c +++ b/nnn.c @@ -129,7 +129,7 @@ #endif /* Global context */ static struct entry *dents; -static int ndents, cur; +static int ndents, cur, total_dents; static int idle; static char *opener; static char *fallback_opener; @@ -239,7 +239,7 @@ static char * xdirname(const char *path) { static char buf[PATH_MAX]; - char *last_slash; + static char *last_slash; xstrlcpy(buf, path, PATH_MAX); @@ -366,6 +366,7 @@ return (int) (TOUPPER(*s1) - TOUPPER(*s2)); } +/* Trim all white space from both ends */ static char * strstrip(char *s) { @@ -411,9 +412,9 @@ static int setfilter(regex_t *regex, char *filter) { - char errbuf[LINE_MAX]; - size_t len; - int r; + static char errbuf[LINE_MAX]; + static size_t len; + static int r; r = regcomp(regex, filter, REG_NOSUB | REG_EXTENDED | REG_ICASE); if (r != 0) { @@ -1034,8 +1035,9 @@ if (filter(re, dp->d_name) == 0) continue; - if (((n >> 5) << 5) == n) { - *dents = realloc(*dents, (n + 32) * sizeof(**dents)); + if (n == total_dents) { + total_dents += 64; + *dents = realloc(*dents, total_dents * sizeof(**dents)); if (*dents == NULL) printerr(1, "realloc"); } @@ -1044,8 +1046,11 @@ xstrlcpy((*dents)[n].name, dp->d_name, sizeof((*dents)[n].name)); /* Get mode flags */ mkpath(path, dp->d_name, newpath, sizeof(newpath)); r = lstat(newpath, &sb); - if (r == -1) + if (r == -1) { + if (*dents) + free(*dents); printerr(1, "lstat"); + } (*dents)[n].mode = sb.st_mode; (*dents)[n].t = sb.st_mtime; (*dents)[n].size = sb.st_size; @@ -1075,8 +1080,11 @@ } /* Should never be null */ r = closedir(dirp); - if (r == -1) + if (r == -1) { + if (*dents) + free(*dents); printerr(1, "closedir"); + } return n; } @@ -1127,11 +1135,6 @@ /* Search filter */ r = setfilter(&re, fltr); if (r != 0) return -1; - - dentfree(dents); - - ndents = 0; - dents = NULL; ndents = dentfill(path, &dents, visible, &re); @@ -1334,14 +1337,13 @@ case S_IFREG: { static char cmd[MAX_CMD_LEN]; static char *runvi = "vi"; - static int status; /* If default mime opener is set, use it */ if (opener) { snprintf(cmd, MAX_CMD_LEN, "%s \"%s\" > /dev/null 2>&1", opener, newpath); - status = system(cmd); + r = system(cmd); continue; } @@ -1370,10 +1372,9 @@ "%s \"%s\" > \ /dev/null 2>&1", fallback_opener, newpath); - status = system(cmd); + r = system(cmd); continue; } else { - status++; /* Dummy operation */ printmsg("No association"); goto nochange; } @@ -1572,9 +1573,11 @@ if (ndents > 0) mkpath(path, dents[cur].name, oldpath, sizeof(oldpath)); r = lstat(oldpath, &sb); - if (r == -1) + if (r == -1) { + if (dents) + dentfree(dents); printerr(1, "lstat"); - else + } else show_stats(oldpath, dents[cur].name, &sb); goto begin;