tled: call dir_context() less frequently in led_render() - neatvi - [fork] simple vi-type editor with UTF-8 support
 (HTM) git clone git://src.adamsgaard.dk/neatvi
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 85f9a4757722e1bc89d9e2ea84cdf98361e6899c
 (DIR) parent a1a91f49480b499d8ad0c64a37554e7677db483c
 (HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
       Date:   Wed, 20 May 2015 19:06:21 +0430
       
       led: call dir_context() less frequently in led_render()
       
       Diffstat:
         M led.c                               |      12 +++++++++---
       
       1 file changed, 9 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/led.c b/led.c
       t@@ -30,6 +30,11 @@ int led_pos(char *s, int pos)
                return dir_context(s) >= 0 ? pos : xcols - pos - 1;
        }
        
       +static int led_posctx(int dir, int pos)
       +{
       +        return dir >= 0 ? pos : xcols - pos - 1;
       +}
       +
        char *led_keymap(char *kmap, int c)
        {
                return c >= 0 ? kmap_map(kmap, c) : NULL;
       t@@ -43,6 +48,7 @@ static char *led_render(char *s0)
                char **chrs;        /* chrs[i]: the i-th character in s1 */
                struct sbuf *out;
                int i, j;
       +        int ctx = dir_context(s0);
                chrs = uc_chop(s0, &n);
                pos = ren_position(s0);
                off = malloc(xcols * sizeof(off[0]));
       t@@ -52,9 +58,9 @@ static char *led_render(char *s0)
                        int curwid = ren_cwid(chrs[i], curpos);
                        if (curpos >= 0 && curpos + curwid < xcols) {
                                for (j = 0; j < curwid; j++) {
       -                                off[led_pos(s0, curpos + j)] = i;
       -                                if (led_pos(s0, curpos + j) > maxcol)
       -                                        maxcol = led_pos(s0, curpos + j);
       +                                off[led_posctx(ctx, curpos + j)] = i;
       +                                if (led_posctx(ctx, curpos + j) > maxcol)
       +                                        maxcol = led_posctx(ctx, curpos + j);
                                }
                        }
                }