From 67057e32b8d8b03c52d22f1067ff1e4f9b023a60 Mon Sep 17 00:00:00 2001 From: skimo Date: Fri, 21 Jul 2000 17:35:02 +0000 Subject: [PATCH] small screen updating optimization in gtk front end --- common/conv.c | 3 ++- common/key.h | 6 +----- common/multibyte.h | 8 ++++++-- common/seq.c | 4 ++-- common/util.c | 16 ++-------------- common/util2.c | 28 ++++++++++++++++++++++++++++ dist/Makefile.am | 7 +++++++ gtk/gtkviscreen.c | 34 +++++++++++++++++++--------------- gtk/gtkviscreen.h | 1 + regex/engine.c | 2 +- regex/regcomp.c | 8 ++++---- vi/v_replace.c | 4 ++-- vi/v_txt.c | 6 +++--- 13 files changed, 78 insertions(+), 49 deletions(-) create mode 100644 common/util2.c diff --git a/common/conv.c b/common/conv.c index 1df4590e..d5cade51 100644 --- a/common/conv.c +++ b/common/conv.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: conv.c,v 1.4 2000/07/19 20:31:58 skimo Exp $ (Berkeley) $Date: 2000/07/19 20:31:58 $"; +static const char sccsid[] = "$Id: conv.c,v 1.5 2000/07/21 17:35:02 skimo Exp $ (Berkeley) $Date: 2000/07/21 17:35:02 $"; #endif /* not lint */ #include @@ -148,3 +148,4 @@ conv_enc (SCR *sp, char *enc) } return 1; } + diff --git a/common/key.h b/common/key.h index 4d1da54e..02b4c1e7 100644 --- a/common/key.h +++ b/common/key.h @@ -6,7 +6,7 @@ * * See the LICENSE file for redistribution information. * - * $Id: key.h,v 10.30 2000/07/20 19:21:53 skimo Exp $ (Berkeley) $Date: 2000/07/20 19:21:53 $ + * $Id: key.h,v 10.31 2000/07/21 17:35:02 skimo Exp $ (Berkeley) $Date: 2000/07/21 17:35:02 $ */ #include "multibyte.h" @@ -40,8 +40,6 @@ typedef u_int ARG_CHAR_T; #define INT2DISP(sp,w,wlen,n,nlen) \ sp->conv->int2disp(sp->conv, w, wlen, &n, &nlen) #define CONST -#define CHARSET(s,c,n) \ - v_charset(s,c,n) #else #define FILE2INT(sp,n,nlen,w,wlen) \ w = n, wlen = nlen @@ -54,8 +52,6 @@ typedef u_int ARG_CHAR_T; #define INT2DISP(sp,w,wlen,n,nlen) \ n = w, nlen = wlen #define CONST const -#define CHARSET(s,c,n) \ - memset(s,c,n); #endif #define ISCNTRL(ch) \ diff --git a/common/multibyte.h b/common/multibyte.h index b327483c..b041adb6 100644 --- a/common/multibyte.h +++ b/common/multibyte.h @@ -1,5 +1,6 @@ #ifndef MULTIBYTE_H #define MULTIBYTE_H + #ifdef USE_WIDECHAR typedef int CHAR_T; #define CHAR_T_MAX ((1 << 24)-1) @@ -10,8 +11,11 @@ typedef char CHAR_T; typedef u_char UCHAR_T; #endif -#define MEMCMPW(to, from, n) \ - memcmp(to, from, (n) * sizeof(CHAR_T)) +#define MEMCMP(to, from, n) \ + memcmp(to, from, (n) * sizeof(*(to))) #define MEMMOVE(p, t, len) memmove(p, t, (len) * sizeof(*(p))) +#define MEMCPY(p, t, len) memcpy(p, t, (len) * sizeof(*(p))) +#define STRSET(s,c,n) \ + sizeof(char) == sizeof(CHAR_T) ? memset(s,c,n) : v_strset(s,c,n) #endif diff --git a/common/seq.c b/common/seq.c index 72487f05..30390f01 100644 --- a/common/seq.c +++ b/common/seq.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: seq.c,v 10.13 2000/07/19 20:31:58 skimo Exp $ (Berkeley) $Date: 2000/07/19 20:31:58 $"; +static const char sccsid[] = "$Id: seq.c,v 10.14 2000/07/21 17:35:02 skimo Exp $ (Berkeley) $Date: 2000/07/21 17:35:02 $"; #endif /* not lint */ #include @@ -212,7 +212,7 @@ seq_find(sp, lastqp, e_input, c_input, ilen, stype, ispartialp) if (qp->input[0] < c_input[0] || qp->stype != stype || F_ISSET(qp, SEQ_FUNCMAP)) continue; - diff = MEMCMPW(qp->input, c_input, MIN(qp->ilen, ilen)); + diff = MEMCMP(qp->input, c_input, MIN(qp->ilen, ilen)); } else { if (qp->input[0] > e_input->e_c) break; diff --git a/common/util.c b/common/util.c index 1979148a..213a2c72 100644 --- a/common/util.c +++ b/common/util.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: util.c,v 10.18 2000/07/20 19:21:53 skimo Exp $ (Berkeley) $Date: 2000/07/20 19:21:53 $"; +static const char sccsid[] = "$Id: util.c,v 10.19 2000/07/21 17:35:02 skimo Exp $ (Berkeley) $Date: 2000/07/21 17:35:02 $"; #endif /* not lint */ #include @@ -176,19 +176,7 @@ v_strlen(const CHAR_T *str) } /* - * PUBLIC: void * v_charset __P((CHAR_T *s, CHAR_T c, size_t n)); - */ -void * -v_charset(CHAR_T *s, CHAR_T c, size_t n) -{ - CHAR_T *ss = s; - - while (n--) *s++ = c; - return ss; -} - -/* - * PUBLIC: int v_strcmp __P((const CHAR_T *s1, const CHAR_T *s2)) + * PUBLIC: int v_strcmp __P((const CHAR_T *s1, const CHAR_T *s2)); */ int v_strcmp(const CHAR_T *s1, const CHAR_T *s2) diff --git a/common/util2.c b/common/util2.c new file mode 100644 index 00000000..5b22b550 --- /dev/null +++ b/common/util2.c @@ -0,0 +1,28 @@ +#include "config.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "multibyte.h" + +/* + * PUBLIC: void * v_strset __P((CHAR_T *s, CHAR_T c, size_t n)); + */ +void * +v_strset(CHAR_T *s, CHAR_T c, size_t n) +{ + CHAR_T *ss = s; + + while (n--) *s++ = c; + return ss; +} + diff --git a/dist/Makefile.am b/dist/Makefile.am index 014976ed..0fb7d211 100644 --- a/dist/Makefile.am +++ b/dist/Makefile.am @@ -96,6 +96,7 @@ libvi_la_SOURCES = \ $(visrcdir)/common/seq.c \ $(visrcdir)/common/trace.c \ $(visrcdir)/common/util.c \ + $(visrcdir)/common/util2.c \ $(visrcdir)/vi/v_at.c \ $(visrcdir)/vi/v_ch.c \ $(visrcdir)/vi/v_cmd.c \ @@ -140,6 +141,11 @@ EXTRA_libvi_la_SOURCES = \ $(visrcdir)/regex/regerror.c \ $(visrcdir)/regex/regexec.c \ $(visrcdir)/regex/regfree.c \ + $(visrcdir)/regex/cclass.h \ + $(visrcdir)/regex/cname.h \ + $(visrcdir)/regex/regex.h \ + $(visrcdir)/regex/regex2.h \ + $(visrcdir)/regex/utils.h $(visrcdir)/common/dldb.c \ $(visrcdir)/perl_api/perl.xs \ $(visrcdir)/perl_api/perlsfio.c \ @@ -189,6 +195,7 @@ vi_ipc_LDFLAGS = @perlldflags@ vi_ipc_DEPENDENCIES = @IPCOBJS@ vi_gtk_SOURCES = \ + $(visrcdir)/common/util2.c \ $(visrcdir)/ipc/ip_run.c \ $(visrcdir)/ipc/ip_send.c \ $(visrcdir)/ipc/ip_trans.c \ diff --git a/gtk/gtkviscreen.c b/gtk/gtkviscreen.c index ce65b8d9..012a9381 100644 --- a/gtk/gtkviscreen.c +++ b/gtk/gtkviscreen.c @@ -6,6 +6,8 @@ #include "gtkviscreen.h" #include "../common/conv.h" +void * v_strset __P((CHAR_T *s, CHAR_T c, size_t n)); + #define DEFAULT_VI_SCREEN_WIDTH_CHARS 80 #define DEFAULT_VI_SCREEN_HEIGHT_LINES 25 #define VI_SCREEN_BORDER_ROOM 1 @@ -83,32 +85,31 @@ gtk_vi_screen_move(GtkViScreen *vi, gint row, gint col) gint x, xpos; CHAR_T *line; - mark_lines(vi, vi->cury, vi->curx, vi->cury+1, vi->curx+1); line = vi->chars + row*vi->cols; for (x = 0, xpos = 0; xpos <= col; ++x) xpos += INTIS9494(*(line+x)) ? 2 : 1; xpos -= INTIS9494(*(line+--x)) ? 2 : 1; vi->curx = x; vi->cury = row; - mark_lines(vi, vi->cury, vi->curx, vi->cury+1, vi->curx+1); } static void cleartoel (GtkViScreen *vi, guint row, guint col) { - CHAR_T *p, *end; + CHAR_T *p, *e; - p = CharAt(vi,row,col); - end = p + vi->cols - col; - while (p < end) *p++ = ' '; + if (MEMCMP(p = CharAt(vi,row,col), e = CharAt(vi,vi->rows,0), + vi->cols - col)) { + MEMMOVE(p, e, vi->cols - col); + memset(FlagAt(vi,row,col), COLOR_STANDARD, vi->cols - col); + mark_lines(vi, row, col, row+1, vi->cols); + } } void gtk_vi_screen_clrtoel (GtkViScreen *vi) { cleartoel(vi, vi->cury, vi->curx); - memset(FlagAt(vi,vi->cury,vi->curx), COLOR_STANDARD, vi->cols - vi->curx); - mark_lines(vi, vi->cury, vi->curx, vi->cury+1, vi->cols); } void @@ -157,8 +158,7 @@ gtk_vi_screen_deleteln(GtkViScreen *vi) MEMMOVE(CharAt(vi,y,0), CharAt(vi,y+1,0), rows * vi->cols); cleartoel(vi,vi->rows-1,0); memmove(FlagAt(vi,y,0), FlagAt(vi,y+1,0), rows * vi->cols); - memset(FlagAt(vi,vi->rows-1,0), COLOR_STANDARD, vi->cols); - mark_lines(vi, y, 0, vi->rows, vi->cols); + mark_lines(vi, y, 0, vi->rows-1, vi->cols); } void @@ -170,13 +170,16 @@ gtk_vi_screen_insertln(GtkViScreen *vi) MEMMOVE(CharAt(vi,y+1,0), CharAt(vi,y,0), rows * vi->cols); cleartoel(vi,y,0); memmove(FlagAt(vi,y+1,0), FlagAt(vi,y,0), rows * vi->cols); - memset(FlagAt(vi,y,0), COLOR_STANDARD, vi->cols); - mark_lines(vi, y, 0, vi->rows, vi->cols); + mark_lines(vi, y+1, 0, vi->rows, vi->cols); } void gtk_vi_screen_refresh(GtkViScreen *vi) { + if (vi->lastx != vi->curx || vi->lasty != vi-> cury) { + mark_lines(vi, vi->lasty, vi->lastx, vi->lasty+1, vi->lastx+1); + mark_lines(vi, vi->cury, vi->curx, vi->cury+1, vi->curx+1); + } if (vi->marked_maxy == 0) return; draw_lines(vi, vi->marked_y, vi->marked_x, vi->marked_maxy, vi->marked_maxx); @@ -184,6 +187,8 @@ gtk_vi_screen_refresh(GtkViScreen *vi) vi->marked_y = vi->rows; vi->marked_maxx = 0; vi->marked_maxy = 0; + vi->lastx = vi->curx; + vi->lasty = vi->cury; } void @@ -586,9 +591,8 @@ recompute_geometry (GtkViScreen* vi) vi->marked_maxy = 0; g_free(vi->chars); - vi->chars = (CHAR_T*)g_new(gchar, vi->rows*vi->cols * sizeof(CHAR_T)); - for (i = 0; i < vi->rows*vi->cols; ++i) - vi->chars[i] = ' '; + vi->chars = (CHAR_T*)g_new(gchar, (vi->rows+1)*vi->cols * sizeof(CHAR_T)); + STRSET(vi->chars, ' ', (vi->rows+1)*vi->cols); g_free(vi->reverse); vi->reverse = g_new(gchar, vi->rows*vi->cols); memset(vi->reverse, 0, vi->rows*vi->cols); diff --git a/gtk/gtkviscreen.h b/gtk/gtkviscreen.h index 93aee4a9..efa64e6c 100644 --- a/gtk/gtkviscreen.h +++ b/gtk/gtkviscreen.h @@ -32,6 +32,7 @@ struct _GtkViScreen gint cols, rows; gint ch_width, ch_height, ch_ascent; gint curx, cury; + gint lastx, lasty; gint marked_x, marked_y, marked_maxx, marked_maxy; }; diff --git a/regex/engine.c b/regex/engine.c index 561d7193..a1866030 100644 --- a/regex/engine.c +++ b/regex/engine.c @@ -170,7 +170,7 @@ int eflags; if (g->must != NULL) { for (dp = start; dp < stop; dp++) if (*dp == g->must[0] && stop - dp >= g->mlen && - MEMCMPW(dp, g->must, (size_t)g->mlen) == 0) + MEMCMP(dp, g->must, (size_t)g->mlen) == 0) break; if (dp == stop) /* we didn't find g->must */ return(REG_NOMATCH); diff --git a/regex/regcomp.c b/regex/regcomp.c index a166dd37..9e886aa6 100644 --- a/regex/regcomp.c +++ b/regex/regcomp.c @@ -680,12 +680,12 @@ register struct parse *p; static CHAR_T eow[] = { '[', ':', '>', ':', ']', ']' }; /* Dept of Truly Sickening Special-Case Kludges */ - if (p->next + 5 < p->end && MEMCMPW(p->next, bow, 6) == 0) { + if (p->next + 5 < p->end && MEMCMP(p->next, bow, 6) == 0) { EMIT(OBOW, 0); NEXTn(6); return; } - if (p->next + 5 < p->end && MEMCMPW(p->next, eow, 6) == 0) { + if (p->next + 5 < p->end && MEMCMP(p->next, eow, 6) == 0) { EMIT(OEOW, 0); NEXTn(6); return; @@ -827,7 +827,7 @@ register cset *cs; NEXT(); len = p->next - sp; for (cp = cclasses; cp->name != NULL; cp++) - if (v_strlen(cp->name) == len && MEMCMPW(cp->name, sp, len)) + if (v_strlen(cp->name) == len && MEMCMP(cp->name, sp, len)) break; if (cp->name == NULL) { /* oops, didn't find it */ @@ -901,7 +901,7 @@ int endc; /* name ended by endc,']' */ } len = p->next - sp; for (cp = cnames; cp->name != NULL; cp++) - if (v_strlen(cp->name) == len && MEMCMPW(cp->name, sp, len)) + if (v_strlen(cp->name) == len && MEMCMP(cp->name, sp, len)) return(cp->code); /* known name */ if (len == 1) return(*sp); /* single character */ diff --git a/vi/v_replace.c b/vi/v_replace.c index 085d5137..44dda43e 100644 --- a/vi/v_replace.c +++ b/vi/v_replace.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: v_replace.c,v 10.22 2000/07/20 19:21:54 skimo Exp $ (Berkeley) $Date: 2000/07/20 19:21:54 $"; +static const char sccsid[] = "$Id: v_replace.c,v 10.23 2000/07/21 17:35:05 skimo Exp $ (Berkeley) $Date: 2000/07/21 17:35:05 $"; #endif /* not lint */ #include @@ -194,7 +194,7 @@ err_ret: rval = 1; rval = 0; } } else { - CHARSET(bp + vp->m_start.cno, vip->rlast, cnt); + STRSET(bp + vp->m_start.cno, vip->rlast, cnt); rval = db_set(sp, vp->m_start.lno, bp, len); } FREE_SPACEW(sp, bp, blen); diff --git a/vi/v_txt.c b/vi/v_txt.c index 311a46b4..e405a3bc 100644 --- a/vi/v_txt.c +++ b/vi/v_txt.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: v_txt.c,v 10.98 2000/07/16 15:37:25 skimo Exp $ (Berkeley) $Date: 2000/07/16 15:37:25 $"; +static const char sccsid[] = "$Id: v_txt.c,v 10.99 2000/07/21 17:35:05 skimo Exp $ (Berkeley) $Date: 2000/07/21 17:35:05 $"; #endif /* not lint */ #include @@ -2077,7 +2077,7 @@ retry: for (len = 0, case 1: /* One match. */ /* If something changed, do the exchange. */ nlen = v_strlen(cmd.argv[0]->bp); - if (len != nlen || MEMCMPW(cmd.argv[0]->bp, p, len)) + if (len != nlen || MEMCMP(cmd.argv[0]->bp, p, len)) break; /* If haven't done a directory test, do it now. */ @@ -2189,7 +2189,7 @@ txt_fc_col(sp, argc, argv) prefix = (pp - np) + 1; for (ac = argc - 1, av = argv + 1; ac > 0; --ac, ++av) if (av[0]->len < prefix || - MEMCMPW(av[0]->bp, argv[0]->bp, + MEMCMP(av[0]->bp, argv[0]->bp, prefix)) { prefix = 0; break; -- 2.11.4.GIT