diff options
author | lvgx <l@vgx.fr> | 2020-08-21 04:45:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-21 08:15:45 +0530 |
commit | bcbe8080be6610c265bcbc28879502cd9ab72bfc (patch) | |
tree | 572fea1129649f326eb082ecb704cba1db9018cf /src/nnn.c | |
parent | d37356a9362d24436f27bad34219755e7e79642a (diff) | |
download | nnn-bcbe8080be6610c265bcbc28879502cd9ab72bfc.tar.gz |
Add support for Alexey Tourbin's QSORT code (#708)
* Add support for Alexey Tourbin's QSORT code
See https://github.com/svpv/qsort
* Add benchmark scripts and compilation mode
Compile with `make O_BENCHMARK=1`, and run benchmarks with e.g.:
./misc/test/benchmark.sh ./nnn '/' '/usr/bin' '/usr/lib' > benchdata
You can then plot basic violin graphs with:
./misc/test/plot-bench.py benchdata
* Update style, doc, haiku support, fix lint
Diffstat (limited to 'src/nnn.c')
-rw-r--r-- | src/nnn.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -116,6 +116,10 @@ #include "icons.h" #endif +#ifdef TOURBIN_QSORT +#include "qsort.h" +#endif + /* Macro definitions */ #define VERSION "3.4" #define GENERAL_INFO "BSD 2-Clause\nhttps://github.com/jarun/nnn" @@ -732,6 +736,14 @@ static haiku_nm_h haiku_hnd; #define xisdigit(c) ((unsigned int) (c) - '0' <= 9) #define xerror() perror(xitoa(__LINE__)) +#ifdef TOURBIN_QSORT +#define ENTLESS(i,j) (entrycmpfn(pdents + (i), pdents + (j)) < 0) +#define ENTSWAP(i,j) (swap_ent((i),(j))) +#define ENTSORT(pdents, ndents, entrycmpfn) QSORT((ndents), ENTLESS, ENTSWAP) +#else +#define ENTSORT(pdents, ndents, entrycmpfn) qsort((pdents), (ndents), sizeof(*(pdents)), (entrycmpfn)) +#endif + #ifdef __GNUC__ #define UNUSED(x) UNUSED_##x __attribute__((__unused__)) #else @@ -2513,6 +2525,9 @@ static int handle_alt_key(wint_t *wch) */ static int nextsel(int presel) { +#ifdef BENCH + return SEL_QUIT; +#endif int c = presel; uint i; @@ -2710,7 +2725,7 @@ static int matches(const char *fltr) regfree(&re); #endif - qsort(pdents, ndents, sizeof(*pdents), entrycmpfn); + ENTSORT(pdents, ndents, entrycmpfn); return ndents; } @@ -5122,7 +5137,7 @@ static void populate(char *path, char *lastname) if (!ndents) return; - qsort(pdents, ndents, sizeof(*pdents), entrycmpfn); + ENTSORT(pdents, ndents, entrycmpfn); #ifdef DBGMODE clock_gettime(CLOCK_REALTIME, &ts2); @@ -6317,7 +6332,7 @@ nochange: if (r == 'd' || r == 'a') goto begin; - qsort(pdents, ndents, sizeof(*pdents), entrycmpfn); + ENTSORT(pdents, ndents, entrycmpfn); move_cursor(ndents ? dentfind(lastname, ndents) : 0, 0); } continue; |