]> Sergey Matveev's repositories - nnn.git/commitdiff
Various optimizations
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 29 Mar 2017 14:12:23 +0000 (19:42 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 29 Mar 2017 14:12:23 +0000 (19:42 +0530)
README.md
noice.c

index fa8bcd2905734c5da5b6f389135507dd610b9ca1..57bde14e14aac7a3baa6f90d33aaee2e18fb1999 100644 (file)
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ A fork of the [noice](http://git.2f30.org/noice/) file browser to make it more f
 
 ### Introduction
 
-noice is a blazing-fast terminal file browser with easy keyboard shortcuts for navigation, opening files and running tasks. noice is developed with terminal based systems in mind. However, the incredible user-friendliness and speed make it a perfect utility on modern distros.
+noice is a blazing-fast terminal file browser with easy keyboard shortcuts for navigation, opening files and running tasks. noice is developed with terminal based systems in mind. However, the incredible user-friendliness and speed make it a perfect utility on modern distros. Navigate to `/usr/bin` from your regular file browser and noice to feel the difference.
 
 The only issue with noice is hard-coded file association. There is no config file (better performance and simpler to maintain) and you have to modify the source to change associations (see [how to change file associations](#change-file-associations)). This fork solves the problem by adding the flexibility of using the default desktop opener at runtime. There are several other improvements too (see [fork-toppings](#fork-toppings)).
 
diff --git a/noice.c b/noice.c
index 2d562ae8831fd0ceea4d5a0681d355082bc6a9ec..db19ab7b4522c107cb2ca7e7321b191675efeede 100644 (file)
--- a/noice.c
+++ b/noice.c
@@ -281,10 +281,8 @@ entrycmp(const void *va, const void *vb)
 void
 initcurses(void)
 {
-       char *term;
-
        if (initscr() == NULL) {
-               term = getenv("TERM");
+               char *term = getenv("TERM");
                if (term != NULL)
                        fprintf(stderr, "error opening terminal: %s\n", term);
                else
@@ -399,18 +397,14 @@ char *
 mkpath(char *dir, char *name, char *out, size_t n)
 {
        /* Handle absolute path */
-       if (name[0] == '/') {
+       if (name[0] == '/')
                strlcpy(out, name, n);
-       else {
+       else {
                /* Handle root case */
-               if (strcmp(dir, "/") == 0) {
-                       strlcpy(out, "/", n);
-                       strlcat(out, name, n);
-               } else {
-                       strlcpy(out, dir, n);
-                       strlcat(out, "/", n);
-                       strlcat(out, name, n);
-               }
+               if (strcmp(dir, "/") == 0)
+                       snprintf(out, n, "/%s", name);
+               else
+                       snprintf(out, n, "%s/%s", dir, name);
        }
        return out;
 }
@@ -584,15 +578,15 @@ redraw(char *path)
 
        /* Print listing */
        odd = ISODD(nlines);
-       if (cur < nlines / 2) {
+       if (cur < (nlines >> 1)) {
                for (i = 0; i < nlines; i++)
                        printent(&dents[i], i == cur);
-       } else if (cur >= ndents - nlines / 2) {
+       } else if (cur >= ndents - (nlines >> 1)) {
                for (i = ndents - nlines; i < ndents; i++)
                        printent(&dents[i], i == cur);
        } else {
-               for (i = cur - nlines / 2;
-                    i < cur + nlines / 2 + odd; i++)
+               nlines >>= 1;
+               for (i = cur - nlines; i < cur + nlines + odd; i++)
                        printent(&dents[i], i == cur);
        }
 }